12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285 |
- #region MIT License
- /*Copyright (c) 2012 Robert Rouhani <robert.rouhani@gmail.com>
- SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
- Permission is hereby granted, free of charge, to any person obtaining a copy of
- this software and associated documentation files (the "Software"), to deal in
- the Software without restriction, including without limitation the rights to
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- of the Software, and to permit persons to whom the Software is furnished to do
- so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.*/
- #endregion
- using System;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using SharpFont.Bdf;
- using SharpFont.Internal;
- using SharpFont.MultipleMasters;
- using SharpFont.PostScript;
- using SharpFont.TrueType;
- namespace SharpFont
- {
- /// <summary>
- /// FreeType root face class structure. A face object models a typeface in a font file.
- /// </summary>
- /// <remarks>
- /// Fields may be changed after a call to <see cref="AttachFile"/> or <see cref="AttachStream"/>.
- /// </remarks>
- public sealed class Face : IDisposable
- {
- #region Fields
- private IntPtr reference;
- private FaceRec rec;
- private bool disposed;
- private Library parentLibrary;
- private List<FTSize> childSizes;
- #endregion
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="Face"/> class with a default faceIndex of 0.
- /// </summary>
- /// <param name="library">The parent library.</param>
- /// <param name="path">The path of the font file.</param>
- public Face(Library library, string path)
- : this(library, path, 0)
- {
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="Face"/> class.
- /// </summary>
- /// <param name="library">The parent library.</param>
- /// <param name="path">The path of the font file.</param>
- /// <param name="faceIndex">The index of the face to take from the file.</param>
- public Face(Library library, string path, int faceIndex)
- : this()
- {
- IntPtr reference;
- Error err = FT.FT_New_Face(library.Reference, path, faceIndex, out reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- Reference = reference;
- parentLibrary = library;
- parentLibrary.AddChildFace(this);
- }
- //TODO make an overload with a FileStream instead of a byte[]
- /// <summary>
- /// Initializes a new instance of the <see cref="Face"/> class from a file that's already loaded into memory.
- /// </summary>
- /// <param name="library">The parent library.</param>
- /// <param name="file">The loaded file.</param>
- /// <param name="faceIndex">The index of the face to take from the file.</param>
- public unsafe Face(Library library, byte[] file, int faceIndex)
- : this()
- {
- fixed (byte* ptr = file)
- {
- IntPtr reference;
- Error err = FT.FT_New_Memory_Face(library.Reference, (IntPtr)ptr, file.Length, faceIndex, out reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- Reference = reference;
- }
- parentLibrary = library;
- parentLibrary.AddChildFace(this);
- }
- /// <summary>
- /// Initializes a new instance of the Face class.
- /// </summary>
- /// <param name="reference">A pointer to the unmanaged memory containing the Face.</param>
- /// <param name="parent">The parent <see cref="Library"/>.</param>
- internal Face(IntPtr reference, Library parent)
- : this()
- {
- Reference = reference;
- if (parent != null)
- {
- parentLibrary = parent;
- parentLibrary.AddChildFace(this);
- }
- else
- {
- //if there's no parent, this is a marshalled duplicate.
- FT.FT_Reference_Face(Reference);
- }
- }
- private Face()
- {
- childSizes = new List<FTSize>();
- }
- /// <summary>
- /// Finalizes an instance of the Face class.
- /// </summary>
- ~Face()
- {
- Dispose(false);
- }
- #endregion
- #region Properties
- /// <summary>
- /// Gets a value indicating whether the object has been disposed.
- /// </summary>
- public bool IsDisposed
- {
- get
- {
- return disposed;
- }
- }
- /// <summary>
- /// Gets the number of faces in the font file. Some font formats can have multiple faces in a font file.
- /// </summary>
- public int FaceCount
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("FaceCount", "Cannot access a disposed object.");
- return (int)rec.num_faces;
- }
- }
- /// <summary>
- /// Gets the index of the face in the font file. It is set to 0 if there is only one face in the font file.
- /// </summary>
- public int FaceIndex
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("FaceIndex", "Cannot access a disposed object.");
- return (int)rec.face_index;
- }
- }
- /// <summary>
- /// Gets a set of bit flags that give important information about the face.
- /// </summary>
- /// <see cref="FaceFlags"/>
- public FaceFlags FaceFlags
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("FaceFlags", "Cannot access a disposed object.");
- return (FaceFlags)rec.face_flags;
- }
- }
- /// <summary>
- /// Gets a set of bit flags indicating the style of the face.
- /// </summary>
- /// <see cref="StyleFlags"/>
- public StyleFlags StyleFlags
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("StyleFlags", "Cannot access a disposed object.");
- return (StyleFlags)rec.style_flags;
- }
- }
- /// <summary><para>
- /// Gets the number of glyphs in the face. If the face is scalable and has sbits (see ‘num_fixed_sizes’), it is
- /// set to the number of outline glyphs.
- /// </para><para>
- /// For CID-keyed fonts, this value gives the highest CID used in the font.
- /// </para></summary>
- public int GlyphCount
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("GlyphCount", "Cannot access a disposed object.");
- return (int)rec.num_glyphs;
- }
- }
- /// <summary>
- /// Gets the face's family name. This is an ASCII string, usually in English, which describes the typeface's
- /// family (like ‘Times New Roman’, ‘Bodoni’, ‘Garamond’, etc). This is a least common denominator used to list
- /// fonts. Some formats (TrueType & OpenType) provide localized and Unicode versions of this string.
- /// Applications should use the format specific interface to access them. Can be NULL (e.g., in fonts embedded
- /// in a PDF file).
- /// </summary>
- public string FamilyName
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("FamilyName", "Cannot access a disposed object.");
- return rec.family_name;
- }
- }
- /// <summary>
- /// Gets the face's style name. This is an ASCII string, usually in English, which describes the typeface's
- /// style (like ‘Italic’, ‘Bold’, ‘Condensed’, etc). Not all font formats provide a style name, so this field
- /// is optional, and can be set to NULL. As for ‘family_name’, some formats provide localized and Unicode
- /// versions of this string. Applications should use the format specific interface to access them.
- /// </summary>
- public string StyleName
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("StyleName", "Cannot access a disposed object.");
- return rec.style_name;
- }
- }
- /// <summary>
- /// Gets the number of bitmap strikes in the face. Even if the face is scalable, there might still be bitmap
- /// strikes, which are called ‘sbits’ in that case.
- /// </summary>
- public int FixedSizesCount
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("FixedSizesCount", "Cannot access a disposed object.");
- return rec.num_fixed_sizes;
- }
- }
- /// <summary>
- /// Gets an array of FT_Bitmap_Size for all bitmap strikes in the face. It is set to NULL if there is no bitmap
- /// strike.
- /// </summary>
- public BitmapSize[] AvailableSizes
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("AvailableSizes", "Cannot access a disposed object.");
- int count = FixedSizesCount;
- if (count == 0)
- return null;
- BitmapSize[] sizes = new BitmapSize[count];
- IntPtr array = rec.available_sizes;
- for (int i = 0; i < count; i++)
- {
- sizes[i] = new BitmapSize(new IntPtr(array.ToInt64() + IntPtr.Size * i));
- }
- return sizes;
- }
- }
- /// <summary>
- /// Gets the number of charmaps in the face.
- /// </summary>
- public int CharmapsCount
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("CharmapsCount", "Cannot access a disposed object.");
- return rec.num_charmaps;
- }
- }
- /// <summary>
- /// Gets an array of the charmaps of the face.
- /// </summary>
- public CharMap[] CharMaps
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("CharMaps", "Cannot access a disposed object.");
- int count = CharmapsCount;
- if (count == 0)
- return null;
- CharMap[] charmaps = new CharMap[count];
- IntPtr array = rec.charmaps;
- for (int i = 0; i < count; i++)
- {
- charmaps[i] = new CharMap(new IntPtr(array.ToInt64() + IntPtr.Size * i), this);
- }
- return charmaps;
- }
- }
- /// <summary>
- /// Gets or sets a field reserved for client uses.
- /// </summary>
- /// <see cref="Generic"/>
- public Generic Generic
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Generic", "Cannot access a disposed object.");
- return new Generic(rec.generic);
- }
- set
- {
- if (disposed)
- throw new ObjectDisposedException("Generic", "Cannot access a disposed object.");
- //rec.generic = value;
- value.WriteToUnmanagedMemory(new IntPtr(reference.ToInt64() + Marshal.OffsetOf(typeof(FaceRec), "generic").ToInt64()));
- Reference = reference;
- }
- }
- /// <summary><para>
- /// Gets the font bounding box. Coordinates are expressed in font units (see ‘units_per_EM’). The box is large
- /// enough to contain any glyph from the font. Thus, ‘bbox.yMax’ can be seen as the ‘maximal ascender’, and
- /// ‘bbox.yMin’ as the ‘minimal descender’. Only relevant for scalable formats.
- /// </para><para>
- /// Note that the bounding box might be off by (at least) one pixel for hinted fonts. See FT_Size_Metrics for
- /// further discussion.
- /// </para></summary>
- public BBox BBox
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("BBox", "Cannot access a disposed object.");
- return new BBox(rec.bbox);
- }
- }
- /// <summary>
- /// Gets the number of font units per EM square for this face. This is typically 2048 for TrueType fonts, and
- /// 1000 for Type 1 fonts. Only relevant for scalable formats.
- /// </summary>
- [CLSCompliant(false)]
- public ushort UnitsPerEM
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("UnitsPerEM", "Cannot access a disposed object.");
- return rec.units_per_EM;
- }
- }
- /// <summary>
- /// Gets the typographic ascender of the face, expressed in font units. For font formats not having this
- /// information, it is set to ‘bbox.yMax’. Only relevant for scalable formats.
- /// </summary>
- public short Ascender
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Ascender", "Cannot access a disposed object.");
- return rec.ascender;
- }
- }
- /// <summary>
- /// Gets the typographic descender of the face, expressed in font units. For font formats not having this
- /// information, it is set to ‘bbox.yMin’.Note that this field is usually negative. Only relevant for scalable
- /// formats.
- /// </summary>
- public short Descender
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Descender", "Cannot access a disposed object.");
- return rec.descender;
- }
- }
- /// <summary>
- /// Gets the height is the vertical distance between two consecutive baselines, expressed in font units. It is
- /// always positive. Only relevant for scalable formats.
- /// </summary>
- public short Height
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Height", "Cannot access a disposed object.");
- return rec.height;
- }
- }
- /// <summary>
- /// Gets the maximal advance width, in font units, for all glyphs in this face. This can be used to make word
- /// wrapping computations faster. Only relevant for scalable formats.
- /// </summary>
- public short MaxAdvanceWidth
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("MaxAdvanceWidth", "Cannot access a disposed object.");
- return rec.max_advance_width;
- }
- }
- /// <summary>
- /// Gets the maximal advance height, in font units, for all glyphs in this face. This is only relevant for
- /// vertical layouts, and is set to ‘height’ for fonts that do not provide vertical metrics. Only relevant for
- /// scalable formats.
- /// </summary>
- public short MaxAdvanceHeight
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("MaxAdvanceHeight", "Cannot access a disposed object.");
- return rec.max_advance_height;
- }
- }
- /// <summary>
- /// Gets the position, in font units, of the underline line for this face. It is the center of the underlining
- /// stem. Only relevant for scalable formats.
- /// </summary>
- public short UnderlinePosition
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("UnderlinePosition", "Cannot access a disposed object.");
- return rec.underline_position;
- }
- }
- /// <summary>
- /// Gets the thickness, in font units, of the underline for this face. Only relevant for scalable formats.
- /// </summary>
- public short UnderlineThickness
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("UnderlineThickness", "Cannot access a disposed object.");
- return rec.underline_thickness;
- }
- }
- /// <summary>
- /// Gets the face's associated glyph slot(s).
- /// </summary>
- public GlyphSlot Glyph
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
- return new GlyphSlot(rec.glyph, this, parentLibrary);
- }
- }
- /// <summary>
- /// Gets the current active size for this face.
- /// </summary>
- public FTSize Size
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Size", "Cannot access a disposed object.");
- return new FTSize(rec.size, false, this);
- }
- }
- /// <summary>
- /// Gets the current active charmap for this face.
- /// </summary>
- public CharMap CharMap
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("CharMap", "Cannot access a disposed object.");
- return new CharMap(rec.charmap, this);
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face object contains horizontal metrics (this is true for all font
- /// formats though).
- /// </summary>
- public bool HasHoriziontal
- {
- get
- {
- return (FaceFlags & FaceFlags.Horizontal) == FaceFlags.Horizontal;
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face object contains vertical metrics.
- /// </summary>
- public bool HasVertical
- {
- get
- {
- return (FaceFlags & FaceFlags.Vertical) == FaceFlags.Vertical;
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face object contains kerning data that can be accessed with
- /// <see cref="GetKerning"/>.
- /// </summary>
- public bool HasKerning
- {
- get
- {
- return (FaceFlags & FaceFlags.Kerning) == FaceFlags.Kerning;
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face object contains a scalable font face (true for TrueType, Type 1,
- /// Type 42, CID, OpenType/CFF, and PFR font formats.
- /// </summary>
- public bool IsScalable
- {
- get
- {
- return (FaceFlags & FaceFlags.Scalable) == FaceFlags.Scalable;
- }
- }
- /// <summary><para>
- /// Gets a value indicating whether a face object contains a font whose format is based on the SFNT storage
- /// scheme. This usually means: TrueType fonts, OpenType fonts, as well as SFNT-based embedded bitmap fonts.
- /// </para><para>
- /// If this macro is true, all functions defined in FT_SFNT_NAMES_H and FT_TRUETYPE_TABLES_H are available.
- /// </para></summary>
- public bool IsSfnt
- {
- get
- {
- return (FaceFlags & FaceFlags.Sfnt) == FaceFlags.Sfnt;
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face object contains a font face that contains fixed-width (or
- /// ‘monospace’, ‘fixed-pitch’, etc.) glyphs.
- /// </summary>
- public bool IsFixedWidth
- {
- get
- {
- return (FaceFlags & FaceFlags.FixedWidth) == FaceFlags.FixedWidth;
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face object contains some embedded bitmaps.
- /// </summary>
- /// <see cref="Face.AvailableSizes"/>
- public bool HasFixedSizes
- {
- get
- {
- return (FaceFlags & FaceFlags.FixedSizes) == FaceFlags.FixedSizes;
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face object contains some glyph names that can be accessed through
- /// <see cref="GetGlyphName(uint, int)"/>.
- /// </summary>
- public bool HasGlyphNames
- {
- get
- {
- return (FaceFlags & FaceFlags.GlyphNames) == FaceFlags.GlyphNames;
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face object contains some multiple masters. The functions provided by
- /// FT_MULTIPLE_MASTERS_H are then available to choose the exact design you want.
- /// </summary>
- public bool HasMultipleMasters
- {
- get
- {
- return (FaceFlags & FaceFlags.MultipleMasters) == FaceFlags.MultipleMasters;
- }
- }
- /// <summary><para>
- /// Gets a value indicating whether a face object contains a CID-keyed font. See the discussion of
- /// FT_FACE_FLAG_CID_KEYED for more details.
- /// </para><para>
- /// If this macro is true, all functions defined in FT_CID_H are available.
- /// </para></summary>
- public bool IsCidKeyed
- {
- get
- {
- return (FaceFlags & FaceFlags.CidKeyed) == FaceFlags.CidKeyed;
- }
- }
- /// <summary>
- /// Gets a value indicating whether a face represents a ‘tricky’ font. See the discussion of
- /// FT_FACE_FLAG_TRICKY for more details.
- /// </summary>
- public bool IsTricky
- {
- get
- {
- return (FaceFlags & FaceFlags.Tricky) == FaceFlags.Tricky;
- }
- }
- internal IntPtr Reference
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
- return reference;
- }
- set
- {
- if (disposed)
- throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
- reference = value;
- rec = PInvokeHelper.PtrToStructure<FaceRec>(reference);
- }
- }
- #endregion
- #region Methods
- #region FreeType Version
- /// <summary><para>
- /// Parse all bytecode instructions of a TrueType font file to check whether any of the patented opcodes are
- /// used. This is only useful if you want to be able to use the unpatented hinter with fonts that do not use
- /// these opcodes.
- /// </para><para>
- /// Note that this function parses all glyph instructions in the font file, which may be slow.
- /// </para></summary>
- /// <remarks>
- /// Since May 2010, TrueType hinting is no longer patented.
- /// </remarks>
- /// <returns>True if this is a TrueType font that uses one of the patented opcodes, false otherwise.</returns>
- public bool CheckTrueTypePatents()
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Face_CheckTrueTypePatents(Reference);
- }
- /// <summary>
- /// Enable or disable the unpatented hinter for a given <see cref="Face"/>. Only enable it if you have
- /// determined that the face doesn't use any patented opcodes.
- /// </summary>
- /// <remarks>
- /// Since May 2010, TrueType hinting is no longer patented.
- /// </remarks>
- /// <param name="value">New boolean setting.</param>
- /// <returns>
- /// The old setting value. This will always be false if this is not an SFNT font, or if the unpatented hinter
- /// is not compiled in this instance of the library.
- /// </returns>
- /// <see cref="CheckTrueTypePatents"/>
- public bool SetUnpatentedHinting(bool value)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Face_SetUnpatentedHinting(Reference, value);
- }
- #endregion
- #region Base Interface
- /// <summary>
- /// This function calls <see cref="AttachStream"/> to attach a file.
- /// </summary>
- /// <param name="path">The pathname.</param>
- public void AttachFile(string path)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Attach_File(Reference, path);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// ‘Attach’ data to a face object. Normally, this is used to read additional information for the face object.
- /// For example, you can attach an AFM file that comes with a Type 1 font to get the kerning values and other
- /// metrics.
- /// </summary>
- /// <remarks><para>
- /// The meaning of the ‘attach’ (i.e., what really happens when the new file is read) is not fixed by FreeType
- /// itself. It really depends on the font format (and thus the font driver).
- /// </para><para>
- /// Client applications are expected to know what they are doing when invoking this function. Most drivers
- /// simply do not implement file attachments.
- /// </para></remarks>
- /// <param name="parameters">A pointer to <see cref="OpenArgs"/> which must be filled by the caller.</param>
- public void AttachStream(OpenArgs parameters)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Attach_Stream(Reference, parameters.Reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Select a bitmap strike.
- /// </summary>
- /// <param name="strikeIndex">
- /// The index of the bitmap strike in the <see cref="Face.AvailableSizes"/> field of <see cref="Face"/>
- /// structure.
- /// </param>
- public void SelectSize(int strikeIndex)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Select_Size(Reference, strikeIndex);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Resize the scale of the active <see cref="FTSize"/> object in a face.
- /// </summary>
- /// <param name="request">A pointer to a <see cref="SizeRequest"/>.</param>
- public void RequestSize(SizeRequest request)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Request_Size(Reference, request.Reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// This function calls <see cref="RequestSize"/> to request the nominal size (in points).
- /// </summary>
- /// <remarks><para>
- /// If either the character width or height is zero, it is set equal to the other value.
- /// </para><para>
- /// If either the horizontal or vertical resolution is zero, it is set equal to the other value.
- /// </para><para>
- /// A character width or height smaller than 1pt is set to 1pt; if both resolution values are zero, they are
- /// set to 72dpi.
- /// </para></remarks>
- /// <param name="width">The nominal width, in 26.6 fractional points.</param>
- /// <param name="height">The nominal height, in 26.6 fractional points.</param>
- /// <param name="horizontalResolution">The horizontal resolution in dpi.</param>
- /// <param name="verticalResolution">The vertical resolution in dpi.</param>
- [CLSCompliant(false)]
- public void SetCharSize(int width, int height, uint horizontalResolution, uint verticalResolution)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Set_Char_Size(Reference, width, height, horizontalResolution, verticalResolution);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// This function calls <see cref="RequestSize"/> to request the nominal size (in pixels).
- /// </summary>
- /// <param name="width">The nominal width, in pixels.</param>
- /// <param name="height">The nominal height, in pixels</param>
- [CLSCompliant(false)]
- public void SetPixelSizes(uint width, uint height)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Set_Pixel_Sizes(Reference, width, height);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// A function used to load a single glyph into the glyph slot of a face object.
- /// </summary>
- /// <remarks><para>
- /// The loaded glyph may be transformed. See <see cref="SetTransform"/> for the details.
- /// </para><para>
- /// For subsetted CID-keyed fonts, <see cref="Error.InvalidArgument"/> is returned for invalid CID values (this
- /// is, for CID values which don't have a corresponding glyph in the font). See the discussion of the
- /// <see cref="SharpFont.FaceFlags.CidKeyed"/> flag for more details.
- /// </para></remarks>
- /// <param name="glyphIndex">
- /// The index of the glyph in the font file. For CID-keyed fonts (either in PS or in CFF format) this argument
- /// specifies the CID value.
- /// </param>
- /// <param name="flags">
- /// A flag indicating what to load for this glyph. The <see cref="LoadFlags"/> constants can be used to control
- /// the glyph loading process (e.g., whether the outline should be scaled, whether to load bitmaps or not,
- /// whether to hint the outline, etc).
- /// </param>
- /// <param name="target">The target to OR with the flags.</param>
- [CLSCompliant(false)]
- public void LoadGlyph(uint glyphIndex, LoadFlags flags, LoadTarget target)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Load_Glyph(Reference, glyphIndex, (int)flags | (int)target);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// A function used to load a single glyph into the glyph slot of a face object, according to its character
- /// code.
- /// </summary>
- /// <remarks>
- /// This function simply calls <see cref="GetCharIndex"/> and <see cref="LoadGlyph"/>
- /// </remarks>
- /// <param name="charCode">
- /// The glyph's character code, according to the current charmap used in the face.
- /// </param>
- /// <param name="flags">
- /// A flag indicating what to load for this glyph. The <see cref="LoadFlags"/> constants can be used to control
- /// the glyph loading process (e.g., whether the outline should be scaled, whether to load bitmaps or not,
- /// whether to hint the outline, etc).
- /// </param>
- /// <param name="target">The target to OR with the flags.</param>
- [CLSCompliant(false)]
- public void LoadChar(uint charCode, LoadFlags flags, LoadTarget target)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Load_Char(Reference, charCode, (int)flags | (int)target);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// A function used to set the transformation that is applied to glyph images when they are loaded into a glyph
- /// slot through <see cref="LoadGlyph"/>.
- /// </summary>
- /// <remarks><para>
- /// The transformation is only applied to scalable image formats after the glyph has been loaded. It means that
- /// hinting is unaltered by the transformation and is performed on the character size given in the last call to
- /// <see cref="SetCharSize"/> or <see cref="SetPixelSizes"/>.
- /// </para><para>
- /// Note that this also transforms the ‘face.glyph.advance’ field, but not the values in ‘face.glyph.metrics’.
- /// </para></remarks>
- /// <param name="matrix">A pointer to the transformation's 2x2 matrix. Use 0 for the identity matrix.</param>
- /// <param name="delta">A pointer to the translation vector. Use 0 for the null vector.</param>
- public void SetTransform(FTMatrix matrix, FTVector delta)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- FT.FT_Set_Transform(Reference, ref matrix, ref delta);
- }
- /// <summary>
- /// Return the kerning vector between two glyphs of a same face.
- /// </summary>
- /// <remarks>
- /// Only horizontal layouts (left-to-right & right-to-left) are supported by this method. Other layouts, or
- /// more sophisticated kernings, are out of the scope of this API function -- they can be implemented through
- /// format-specific interfaces.
- /// </remarks>
- /// <param name="leftGlyph">The index of the left glyph in the kern pair.</param>
- /// <param name="rightGlyph">The index of the right glyph in the kern pair.</param>
- /// <param name="mode">Determines the scale and dimension of the returned kerning vector.</param>
- /// <returns>
- /// The kerning vector. This is either in font units or in pixels (26.6 format) for scalable formats, and in
- /// pixels for fixed-sizes formats.
- /// </returns>
- [CLSCompliant(false)]
- public FTVector GetKerning(uint leftGlyph, uint rightGlyph, KerningMode mode)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- FTVector kern;
- Error err = FT.FT_Get_Kerning(Reference, leftGlyph, rightGlyph, mode, out kern);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return kern;
- }
- /// <summary>
- /// Return the track kerning for a given face object at a given size.
- /// </summary>
- /// <param name="pointSize">The point size in 16.16 fractional points.</param>
- /// <param name="degree">The degree of tightness.</param>
- /// <returns>The kerning in 16.16 fractional points.</returns>
- public int GetTrackKerning(int pointSize, int degree)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- int kerning;
- Error err = FT.FT_Get_Track_Kerning(Reference, pointSize, degree, out kerning);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return kerning;
- }
- /// <summary>
- /// Retrieve the ASCII name of a given glyph in a face. This only works for those faces where
- /// <see cref="HasGlyphNames"/> returns 1.
- /// </summary>
- /// <remarks><para>
- /// An error is returned if the face doesn't provide glyph names or if the glyph index is invalid. In all cases
- /// of failure, the first byte of ‘buffer’ is set to 0 to indicate an empty name.
- /// </para><para>
- /// The glyph name is truncated to fit within the buffer if it is too long. The returned string is always
- /// zero-terminated.
- /// </para><para>
- /// Be aware that FreeType reorders glyph indices internally so that glyph index 0 always corresponds to the
- /// ‘missing glyph’ (called ‘.notdef’).
- /// </para><para>
- /// This function is not compiled within the library if the config macro ‘FT_CONFIG_OPTION_NO_GLYPH_NAMES’ is
- /// defined in ‘include/freetype/config/ftoptions.h’.
- /// </para></remarks>
- /// <param name="glyphIndex">The glyph index.</param>
- /// <param name="bufferSize">The maximal number of bytes available in the buffer.</param>
- /// <returns>The ASCII name of a given glyph in a face.</returns>
- [CLSCompliant(false)]
- public string GetGlyphName(uint glyphIndex, int bufferSize)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return GetGlyphName(glyphIndex, new byte[bufferSize]);
- }
- /// <summary>
- /// Retrieve the ASCII name of a given glyph in a face. This only works for those faces where
- /// <see cref="HasGlyphNames"/> returns 1.
- /// </summary>
- /// <remarks><para>
- /// An error is returned if the face doesn't provide glyph names or if the glyph index is invalid. In all cases
- /// of failure, the first byte of ‘buffer’ is set to 0 to indicate an empty name.
- /// </para><para>
- /// The glyph name is truncated to fit within the buffer if it is too long. The returned string is always
- /// zero-terminated.
- /// </para><para>
- /// Be aware that FreeType reorders glyph indices internally so that glyph index 0 always corresponds to the
- /// ‘missing glyph’ (called ‘.notdef’).
- /// </para><para>
- /// This function is not compiled within the library if the config macro ‘FT_CONFIG_OPTION_NO_GLYPH_NAMES’ is
- /// defined in ‘include/freetype/config/ftoptions.h’.
- /// </para></remarks>
- /// <param name="glyphIndex">The glyph index.</param>
- /// <param name="buffer">The target buffer where the name is copied to.</param>
- /// <returns>The ASCII name of a given glyph in a face.</returns>
- [CLSCompliant(false)]
- public unsafe string GetGlyphName(uint glyphIndex, byte[] buffer)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- fixed (byte* ptr = buffer)
- {
- IntPtr intptr = new IntPtr(ptr);
- Error err = FT.FT_Get_Glyph_Name(Reference, glyphIndex, intptr, (uint)buffer.Length);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return Marshal.PtrToStringAnsi(intptr);
- }
- }
- /// <summary>
- /// Retrieve the ASCII Postscript name of a given face, if available. This only works with Postscript and
- /// TrueType fonts.
- /// </summary>
- /// <remarks>
- /// The returned pointer is owned by the face and is destroyed with it.
- /// </remarks>
- /// <returns>A pointer to the face's Postscript name. NULL if unavailable.</returns>
- public string GetPostscriptName()
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return Marshal.PtrToStringAnsi(FT.FT_Get_Postscript_Name(Reference));
- }
- /// <summary>
- /// Select a given charmap by its encoding tag (as listed in ‘freetype.h’).
- /// </summary>
- /// <remarks><para>
- /// This function returns an error if no charmap in the face corresponds to the encoding queried here.
- /// </para><para>
- /// Because many fonts contain more than a single cmap for Unicode encoding, this function has some special
- /// code to select the one which covers Unicode best. It is thus preferable to <see cref="SetCharmap"/> in
- /// this case.
- /// </para></remarks>
- /// <param name="encoding">A handle to the selected encoding.</param>
- [CLSCompliant(false)]
- public void SelectCharmap(Encoding encoding)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Select_Charmap(Reference, encoding);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Select a given charmap for character code to glyph index mapping.
- /// </summary>
- /// <remarks>
- /// This function returns an error if the charmap is not part of the face (i.e., if it is not listed in the
- /// <see cref="Face.CharMaps"/>’ table).
- /// </remarks>
- /// <param name="charmap">A handle to the selected charmap.</param>
- public void SetCharmap(CharMap charmap)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- Error err = FT.FT_Set_Charmap(Reference, charmap.Reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Return the glyph index of a given character code. This function uses a charmap object to do the mapping.
- /// </summary>
- /// <remarks>
- /// If you use FreeType to manipulate the contents of font files directly, be aware that the glyph index
- /// returned by this function doesn't always correspond to the internal indices used within the file. This is
- /// done to ensure that value 0 always corresponds to the ‘missing glyph’.
- /// </remarks>
- /// <param name="charCode">The character code.</param>
- /// <returns>The glyph index. 0 means ‘undefined character code’.</returns>
- [CLSCompliant(false)]
- public uint GetCharIndex(uint charCode)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Get_Char_Index(Reference, charCode);
- }
- /// <summary>
- /// This function is used to return the first character code in the current charmap of a given face. It also
- /// returns the corresponding glyph index.
- /// </summary>
- /// <remarks><para>
- /// You should use this function with <see cref="GetNextChar"/> to be able to parse all character codes
- /// available in a given charmap.
- /// </para><para>
- /// Note that ‘agindex’ is set to 0 if the charmap is empty. The result itself can be 0 in two cases: if the
- /// charmap is empty or when the value 0 is the first valid character code.
- /// </para></remarks>
- /// <param name="glyphIndex">Glyph index of first character code. 0 if charmap is empty.</param>
- /// <returns>The charmap's first character code.</returns>
- [CLSCompliant(false)]
- public uint GetFirstChar(out uint glyphIndex)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Get_First_Char(Reference, out glyphIndex);
- }
- /// <summary>
- /// This function is used to return the next character code in the current charmap of a given face following
- /// the value ‘charCode’, as well as the corresponding glyph index.
- /// </summary>
- /// <remarks><para>
- /// You should use this function with <see cref="GetFirstChar"/> to walk over all character codes available
- /// in a given charmap. See the note for this function for a simple code example.
- /// </para><para>
- /// Note that ‘*agindex’ is set to 0 when there are no more codes in the charmap.
- /// </para></remarks>
- /// <param name="charCode">The starting character code.</param>
- /// <param name="glyphIndex">Glyph index of first character code. 0 if charmap is empty.</param>
- /// <returns>The charmap's next character code.</returns>
- [CLSCompliant(false)]
- public uint GetNextChar(uint charCode, out uint glyphIndex)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Get_Next_Char(Reference, charCode, out glyphIndex);
- }
- /// <summary>
- /// Return the glyph index of a given glyph name. This function uses driver specific objects to do the
- /// translation.
- /// </summary>
- /// <param name="name">The glyph name.</param>
- /// <returns>The glyph index. 0 means ‘undefined character code’.</returns>
- [CLSCompliant(false)]
- public uint GetNameIndex(string name)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Get_Name_Index(Reference, Marshal.StringToHGlobalAuto(name));
- }
- /// <summary>
- /// Return the <see cref="EmbeddingTypes"/> flags for a font.
- /// </summary>
- /// <remarks>
- /// Use this function rather than directly reading the ‘fs_type’ field in the <see cref="PostScript.FontInfo"/>
- /// structure which is only guaranteed to return the correct results for Type 1 fonts.
- /// </remarks>
- /// <returns>The fsType flags, <see cref="EmbeddingTypes"/>.</returns>
- [CLSCompliant(false)]
- public EmbeddingTypes GetFSTypeFlags()
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Get_FSType_Flags(Reference);
- }
- #endregion
- #region Glyph Variants
- /// <summary>
- /// Return the glyph index of a given character code as modified by the variation selector.
- /// </summary>
- /// <remarks><para>
- /// If you use FreeType to manipulate the contents of font files directly, be aware that the glyph index
- /// returned by this function doesn't always correspond to the internal indices used within the file. This is
- /// done to ensure that value 0 always corresponds to the ‘missing glyph’.
- /// </para><para>
- /// This function is only meaningful if a) the font has a variation selector cmap sub table, and b) the current
- /// charmap has a Unicode encoding.
- /// </para></remarks>
- /// <param name="charCode">The character code point in Unicode.</param>
- /// <param name="variantSelector">The Unicode code point of the variation selector.</param>
- /// <returns>
- /// The glyph index. 0 means either ‘undefined character code’, or ‘undefined selector code’, or ‘no variation
- /// selector cmap subtable’, or ‘current CharMap is not Unicode’.
- /// </returns>
- [CLSCompliant(false)]
- public uint GetCharVariantIndex(uint charCode, uint variantSelector)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Face_GetCharVariantIndex(Reference, charCode, variantSelector);
- }
- /// <summary>
- /// Check whether this variant of this Unicode character is the one to be found in the ‘cmap’.
- /// </summary>
- /// <remarks>
- /// This function is only meaningful if the font has a variation selector cmap subtable.
- /// </remarks>
- /// <param name="charCode">The character codepoint in Unicode.</param>
- /// <param name="variantSelector">The Unicode codepoint of the variation selector.</param>
- /// <returns>
- /// 1 if found in the standard (Unicode) cmap, 0 if found in the variation selector cmap, or -1 if it is not a
- /// variant.
- /// </returns>
- [CLSCompliant(false)]
- public int GetCharVariantIsDefault(uint charCode, uint variantSelector)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- return FT.FT_Face_GetCharVariantIsDefault(Reference, charCode, variantSelector);
- }
- /// <summary>
- /// Return a zero-terminated list of Unicode variant selectors found in the font.
- /// </summary>
- /// <remarks>
- /// The last item in the array is 0; the array is owned by the <see cref="Face"/> object but can be overwritten
- /// or released on the next call to a FreeType function.
- /// </remarks>
- /// <returns>
- /// A pointer to an array of selector code points, or NULL if there is no valid variant selector cmap subtable.
- /// </returns>
- [CLSCompliant(false)]
- public uint[] GetVariantSelectors()
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- IntPtr ptr = FT.FT_Face_GetVariantSelectors(Reference);
- List<uint> list = new List<uint>();
- //temporary non-zero value to prevent complaining about uninitialized variable.
- uint curValue = 1;
- for (int i = 0; curValue != 0; i++)
- {
- curValue = (uint)Marshal.ReadInt32(Reference, sizeof(uint) * i);
- list.Add(curValue);
- }
- return list.ToArray();
- }
- /// <summary>
- /// Return a zero-terminated list of Unicode variant selectors found in the font.
- /// </summary>
- /// <remarks>
- /// The last item in the array is 0; the array is owned by the <see cref="Face"/> object but can be overwritten
- /// or released on the next call to a FreeType function.
- /// </remarks>
- /// <param name="charCode">The character codepoint in Unicode.</param>
- /// <returns>
- /// A pointer to an array of variant selector code points which are active for the given character, or NULL if
- /// the corresponding list is empty.
- /// </returns>
- [CLSCompliant(false)]
- public uint[] GetVariantsOfChar(uint charCode)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- IntPtr ptr = FT.FT_Face_GetVariantsOfChar(Reference, charCode);
- List<uint> list = new List<uint>();
- //temporary non-zero value to prevent complaining about uninitialized variable.
- uint curValue = 1;
- for (int i = 0; curValue != 0; i++)
- {
- curValue = (uint)Marshal.ReadInt32(Reference, sizeof(uint) * i);
- list.Add(curValue);
- }
- return list.ToArray();
- }
- /// <summary>
- /// Return a zero-terminated list of Unicode character codes found for the specified variant selector.
- /// </summary>
- /// <remarks>
- /// The last item in the array is 0; the array is owned by the <see cref="Face"/> object but can be overwritten
- /// or released on the next call to a FreeType function.
- /// </remarks>
- /// <param name="variantSelector">The variant selector code point in Unicode.</param>
- /// <returns>
- /// A list of all the code points which are specified by this selector (both default and non-default codes are
- /// returned) or NULL if there is no valid cmap or the variant selector is invalid.
- /// </returns>
- [CLSCompliant(false)]
- public uint[] GetCharsOfVariant(uint variantSelector)
- {
- if (disposed)
- throw new ObjectDisposedException("face", "Cannot access a disposed object.");
- IntPtr ptr = FT.FT_Face_GetCharsOfVariant(Reference, variantSelector);
- List<uint> list = new List<uint>();
- //temporary non-zero value to prevent complaining about uninitialized variable.
- uint curValue = 1;
- for (int i = 0; curValue != 0; i++)
- {
- curValue = (uint)Marshal.ReadInt32(Reference, sizeof(uint) * i);
- list.Add(curValue);
- }
- return list.ToArray();
- }
- #endregion
- #region Size Management
- /// <summary>
- /// Create a new size object from a given face object.
- /// </summary>
- /// <remarks>
- /// You need to call <see cref="FTSize.Activate"/> in order to select the new size for upcoming calls to
- /// <see cref="SetPixelSizes"/>, <see cref="SetCharSize"/>, <see cref="LoadGlyph"/>, <see cref="LoadChar"/>,
- /// etc.
- /// </remarks>
- /// <returns>A handle to a new size object.</returns>
- public FTSize NewSize()
- {
- return new FTSize(this);
- }
- #endregion
- #region Multiple Masters
- /// <summary><para>
- /// Retrieve the Multiple Master descriptor of a given font.
- /// </para><para>
- /// This function can't be used with GX fonts.
- /// </para></summary>
- /// <returns>The Multiple Masters descriptor.</returns>
- public MultiMaster GetMultiMaster()
- {
- IntPtr masterRef;
- Error err = FT.FT_Get_Multi_Master(Reference, out masterRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return new MultiMaster(masterRef);
- }
- /// <summary>
- /// Retrieve the Multiple Master/GX var descriptor of a given font.
- /// </summary>
- /// <returns>
- /// The Multiple Masters/GX var descriptor. Allocates a data structure, which the user must free (a single call
- /// to FT_FREE will do it).
- /// </returns>
- public MMVar GetMMVar()
- {
- IntPtr varRef;
- Error err = FT.FT_Get_MM_Var(Reference, out varRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return new MMVar(varRef);
- }
- /// <summary><para>
- /// For Multiple Masters fonts, choose an interpolated font design through design coordinates.
- /// </para><para>
- /// This function can't be used with GX fonts.
- /// </para></summary>
- /// <param name="coords">An array of design coordinates.</param>
- public unsafe void SetMMDesignCoordinates(long[] coords)
- {
- fixed (void* ptr = coords)
- {
- IntPtr coordsPtr = (IntPtr)ptr;
- Error err = FT.FT_Set_MM_Design_Coordinates(Reference, (uint)coords.Length, coordsPtr);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- }
- /// <summary>
- /// For Multiple Master or GX Var fonts, choose an interpolated font design through design coordinates.
- /// </summary>
- /// <param name="coords">An array of design coordinates.</param>
- public unsafe void SetVarDesignCoordinates(long[] coords)
- {
- fixed (void* ptr = coords)
- {
- IntPtr coordsPtr = (IntPtr)ptr;
- Error err = FT.FT_Set_Var_Design_Coordinates(Reference, (uint)coords.Length, coordsPtr);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- }
- /// <summary>
- /// For Multiple Masters and GX var fonts, choose an interpolated font design through normalized blend
- /// coordinates.
- /// </summary>
- /// <param name="coords">The design coordinates array (each element must be between 0 and 1.0).</param>
- public unsafe void SetMMBlendCoordinates(long[] coords)
- {
- fixed (void* ptr = coords)
- {
- IntPtr coordsPtr = (IntPtr)ptr;
- Error err = FT.FT_Set_MM_Blend_Coordinates(Reference, (uint)coords.Length, coordsPtr);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- }
- /// <summary>
- /// This is another name of <see cref="SetMMBlendCoordinates"/>.
- /// </summary>
- /// <param name="coords">The design coordinates array (each element must be between 0 and 1.0).</param>
- public unsafe void SetVarBlendCoordinates(long[] coords)
- {
- fixed (void* ptr = coords)
- {
- IntPtr coordsPtr = (IntPtr)ptr;
- Error err = FT.FT_Set_Var_Blend_Coordinates(Reference, (uint)coords.Length, coordsPtr);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- }
- #endregion
- #region TrueType Tables
- /// <summary>
- /// Return a pointer to a given SFNT table within a face.
- /// </summary>
- /// <remarks><para>
- /// The table is owned by the face object and disappears with it.
- /// </para><para>
- /// This function is only useful to access SFNT tables that are loaded by the sfnt, truetype, and opentype
- /// drivers. See <see cref="SfntTag"/> for a list.
- /// </para></remarks>
- /// <param name="tag">The index of the SFNT table.</param>
- /// <returns><para>
- /// A type-less pointer to the table. This will be 0 in case of error, or if the corresponding table was not
- /// found OR loaded from the file.
- /// </para><para>
- /// Use a typecast according to ‘tag’ to access the structure elements.
- /// </para></returns>
- public object GetSfntTable(SfntTag tag)
- {
- IntPtr tableRef = FT.FT_Get_Sfnt_Table(Reference, tag);
- if (tableRef == IntPtr.Zero)
- return null;
- switch (tag)
- {
- case SfntTag.Header:
- return new Header(tableRef);
- case SfntTag.HorizontalHeader:
- return new HoriHeader(tableRef);
- case SfntTag.MaxProfile:
- return new MaxProfile(tableRef);
- case SfntTag.OS2:
- return new OS2(tableRef);
- case SfntTag.Pclt:
- return new Pclt(tableRef);
- case SfntTag.Postscript:
- return new Postscript(tableRef);
- case SfntTag.VertHeader:
- return new VertHeader(tableRef);
- default:
- return null;
- }
- }
- /// <summary>
- /// Load any font table into client memory.
- /// </summary>
- /// <remarks>
- /// If you need to determine the table's length you should first call this function with ‘*length’ set to 0, as
- /// in the following example:
- /// <code>
- /// FT_ULong length = 0;
- ///
- ///
- /// error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length );
- /// if ( error ) { ... table does not exist ... }
- ///
- /// buffer = malloc( length );
- /// if ( buffer == NULL ) { ... not enough memory ... }
- ///
- /// error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length );
- /// if ( error ) { ... could not load table ... }
- /// </code>
- /// </remarks>
- /// <param name="tag">
- /// The four-byte tag of the table to load. Use the value 0 if you want to access the whole font file.
- /// Otherwise, you can use one of the definitions found in the FT_TRUETYPE_TAGS_H file, or forge a new one with
- /// FT_MAKE_TAG.
- /// </param>
- /// <param name="offset">The starting offset in the table (or file if tag == 0).</param>
- /// <param name="buffer">
- /// The target buffer address. The client must ensure that the memory array is big enough to hold the data.
- /// </param>
- /// <param name="length"><para>
- /// If the ‘length’ parameter is NULL, then try to load the whole table. Return an error code if it fails.
- /// </para><para>
- /// Else, if ‘*length’ is 0, exit immediately while returning the table's (or file) full size in it.
- /// </para><para>
- /// Else the number of bytes to read from the table or file, from the starting offset.
- /// </para></param>
- [CLSCompliant(false)]
- public void LoadSfntTable(uint tag, int offset, IntPtr buffer, ref uint length)
- {
- Error err = FT.FT_Load_Sfnt_Table(Reference, tag, offset, buffer, ref length);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Return information on an SFNT table.
- /// </summary>
- /// <param name="tableIndex">
- /// The index of an SFNT table. The function returns <see cref="Error.TableMissing"/> for an invalid value.
- /// </param>
- /// <param name="tag">
- /// The name tag of the SFNT table. If the value is NULL, ‘table_index’ is ignored, and ‘length’ returns the
- /// number of SFNT tables in the font.
- /// </param>
- /// <returns>The length of the SFNT table (or the number of SFNT tables, depending on ‘tag’).</returns>
- [CLSCompliant(false)]
- public unsafe uint SfntTableInfo(uint tableIndex, SfntTag tag)
- {
- uint length;
- Error err = FT.FT_Sfnt_Table_Info(Reference, tableIndex, &tag, out length);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return length;
- }
- /// <summary>
- /// Only gets the number of SFNT tables.
- /// </summary>
- /// <returns>The number of SFNT tables.</returns>
- [CLSCompliant(false)]
- public unsafe uint SfntTableInfo()
- {
- uint length;
- Error err = FT.FT_Sfnt_Table_Info(Reference, 0, null, out length);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return length;
- }
- #endregion
- #region Type 1 Tables
- /// <summary><para>
- /// Return true if a given face provides reliable PostScript glyph names. This is similar to using the
- /// <see cref="HasGlyphNames"/> macro, except that certain fonts (mostly TrueType) contain incorrect
- /// glyph name tables.
- /// </para><para>
- /// When this function returns true, the caller is sure that the glyph names returned by
- /// <see cref="GetGlyphName(uint, int)"/> are reliable.
- /// </para></summary>
- /// <returns>Boolean. True if glyph names are reliable.</returns>
- public bool HasPSGlyphNames()
- {
- return FT.FT_Has_PS_Glyph_Names(Reference);
- }
- /// <summary>
- /// Retrieve the <see cref="PostScript.FontInfo"/> structure corresponding to a given PostScript font.
- /// </summary>
- /// <remarks><para>
- /// The string pointers within the font info structure are owned by the face and don't need to be freed by the
- /// caller.
- /// </para><para>
- /// If the font's format is not PostScript-based, this function will return the
- /// <see cref="Error.InvalidArgument"/> error code.
- /// </para></remarks>
- /// <returns>Output font info structure pointer.</returns>
- public FontInfo GetPSFontInfo()
- {
- IntPtr fontInfoRef;
- Error err = FT.FT_Get_PS_Font_Info(Reference, out fontInfoRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return new FontInfo(fontInfoRef);
- }
- /// <summary>
- /// Retrieve the <see cref="PostScript.Private"/> structure corresponding to a given PostScript font.
- /// </summary>
- /// <remarks><para>
- /// The string pointers within the <see cref="PostScript.Private"/> structure are owned by the face and don't
- /// need to be freed by the caller.
- /// </para><para>
- /// If the font's format is not PostScript-based, this function returns the <see cref="Error.InvalidArgument"/>
- /// error code.
- /// </para></remarks>
- /// <returns>Output private dictionary structure pointer.</returns>
- public Private GetPSFontPrivate()
- {
- IntPtr privateRef;
- Error err = FT.FT_Get_PS_Font_Private(Reference, out privateRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return new Private(privateRef);
- }
- /// <summary>
- /// Retrieve the value for the supplied key from a PostScript font.
- /// </summary>
- /// <remarks><para>
- /// The values returned are not pointers into the internal structures of the face, but are ‘fresh’ copies, so
- /// that the memory containing them belongs to the calling application. This also enforces the ‘read-only’
- /// nature of these values, i.e., this function cannot be used to manipulate the face.
- /// </para><para>
- /// ‘value’ is a void pointer because the values returned can be of various types.
- /// </para><para>
- /// If either ‘value’ is NULL or ‘value_len’ is too small, just the required memory size for the requested
- /// entry is returned.
- /// </para><para>
- /// The ‘idx’ parameter is used, not only to retrieve elements of, for example, the FontMatrix or FontBBox, but
- /// also to retrieve name keys from the CharStrings dictionary, and the charstrings themselves. It is ignored
- /// for atomic values.
- /// </para><para>
- /// <see cref="PostScript.DictionaryKeys.BlueScale"/> returns a value that is scaled up by 1000. To get the
- /// value as in the font stream, you need to divide by 65536000.0 (to remove the FT_Fixed scale, and the x1000
- /// scale).
- /// </para><para>
- /// IMPORTANT: Only key/value pairs read by the FreeType interpreter can be retrieved. So, for example,
- /// PostScript procedures such as NP, ND, and RD are not available. Arbitrary keys are, obviously, not be
- /// available either.
- /// </para><para>
- /// If the font's format is not PostScript-based, this function returns the <see cref="Error.InvalidArgument"/>
- /// error code.
- /// </para></remarks>
- /// <param name="key">An enumeration value representing the dictionary key to retrieve.</param>
- /// <param name="idx">For array values, this specifies the index to be returned.</param>
- /// <param name="value">A pointer to memory into which to write the value.</param>
- /// <param name="valueLength">The size, in bytes, of the memory supplied for the value.</param>
- /// <returns>
- /// The amount of memory (in bytes) required to hold the requested value (if it exists, -1 otherwise).
- /// </returns>
- [CLSCompliant(false)]
- public int GetPSFontValue(DictionaryKeys key, uint idx, ref IntPtr value, int valueLength)
- {
- return FT.FT_Get_PS_Font_Value(Reference, key, idx, ref value, valueLength);
- }
- #endregion
- #region SFNT Names
- /// <summary>
- /// Retrieve the number of name strings in the SFNT ‘name’ table.
- /// </summary>
- /// <returns>The number of strings in the ‘name’ table.</returns>
- [CLSCompliant(false)]
- public uint GetSfntNameCount()
- {
- return FT.FT_Get_Sfnt_Name_Count(Reference);
- }
- /// <summary>
- /// Retrieve a string of the SFNT ‘name’ table for a given index.
- /// </summary>
- /// <remarks><para>
- /// The ‘string’ array returned in the ‘aname’ structure is not null-terminated. The application should
- /// deallocate it if it is no longer in use.
- /// </para><para>
- /// Use <see cref="GetSfntNameCount"/> to get the total number of available ‘name’ table entries, then do a
- /// loop until you get the right platform, encoding, and name ID.
- /// </para></remarks>
- /// <param name="idx">The index of the ‘name’ string.</param>
- /// <returns>The indexed <see cref="SfntName"/> structure.</returns>
- [CLSCompliant(false)]
- public SfntName GetSfntName(uint idx)
- {
- IntPtr nameRef;
- Error err = FT.FT_Get_Sfnt_Name(Reference, idx, out nameRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return new SfntName(nameRef);
- }
- #endregion
- #region BDF and PCF Files
- /// <summary>
- /// Retrieve a BDF font character set identity, according to the BDF specification.
- /// </summary>
- /// <remarks>
- /// This function only works with BDF faces, returning an error otherwise.
- /// </remarks>
- /// <param name="encoding">Charset encoding, as a C string, owned by the face.</param>
- /// <param name="registry">Charset registry, as a C string, owned by the face.</param>
- public void GetBdfCharsetId(out string encoding, out string registry)
- {
- Error err = FT.FT_Get_BDF_Charset_ID(Reference, out encoding, out registry);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Retrieve a BDF property from a BDF or PCF font file.
- /// </summary>
- /// <remarks><para>
- /// This function works with BDF and PCF fonts. It returns an error otherwise. It also returns an error if the
- /// property is not in the font.
- /// </para><para>
- /// A ‘property’ is a either key-value pair within the STARTPROPERTIES ... ENDPROPERTIES block of a BDF font or
- /// a key-value pair from the ‘info->props’ array within a ‘FontRec’ structure of a PCF font.
- /// </para><para>
- /// Integer properties are always stored as ‘signed’ within PCF fonts; consequently,
- /// <see cref="PropertyType.Cardinal"/> is a possible return value for BDF fonts only.
- /// </para><para>
- /// In case of error, ‘aproperty->type’ is always set to <see cref="PropertyType.None"/>.
- /// </para></remarks>
- /// <param name="propertyName">The property name.</param>
- /// <returns>The property.</returns>
- public Property GetBdfProperty(string propertyName)
- {
- IntPtr propertyRef;
- Error err = FT.FT_Get_BDF_Property(Reference, propertyName, out propertyRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return new Property(propertyRef);
- }
- #endregion
- #region CID Fonts
- /// <summary>
- /// Retrieve the Registry/Ordering/Supplement triple (also known as the "R/O/S") from a CID-keyed font.
- /// </summary>
- /// <remarks>
- /// This function only works with CID faces, returning an error otherwise.
- /// </remarks>
- /// <param name="registry">The registry, as a C string, owned by the face.</param>
- /// <param name="ordering">The ordering, as a C string, owned by the face.</param>
- /// <param name="supplement">The supplement.</param>
- public void GetCidRegistryOrderingSupplement(out string registry, out string ordering, out int supplement)
- {
- Error err = FT.FT_Get_CID_Registry_Ordering_Supplement(Reference, out registry, out ordering, out supplement);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Retrieve the type of the input face, CID keyed or not. In constrast to the
- /// <see cref="IsCidKeyed"/> macro this function returns successfully also for CID-keyed fonts in an
- /// SNFT wrapper.
- /// </summary>
- /// <remarks>
- /// This function only works with CID faces and OpenType fonts, returning an error otherwise.
- /// </remarks>
- /// <returns>The type of the face as an FT_Bool.</returns>
- public bool GetCidIsInternallyCidKeyed()
- {
- byte is_cid;
- Error err = FT.FT_Get_CID_Is_Internally_CID_Keyed(Reference, out is_cid);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return is_cid == 1;
- }
- /// <summary>
- /// Retrieve the CID of the input glyph index.
- /// </summary>
- /// <remarks>
- /// This function only works with CID faces and OpenType fonts, returning an error otherwise.
- /// </remarks>
- /// <param name="glyphIndex">The input glyph index.</param>
- /// <returns>The CID as an uint.</returns>
- [CLSCompliant(false)]
- public uint GetCidFromGlyphIndex(uint glyphIndex)
- {
- uint cid;
- Error err = FT.FT_Get_CID_From_Glyph_Index(Reference, glyphIndex, out cid);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return cid;
- }
- #endregion
- #region PFR Fonts
- /// <summary>
- /// Return the outline and metrics resolutions of a given PFR face.
- /// </summary>
- /// <remarks>
- /// If the input face is not a PFR, this function will return an error. However, in all cases, it will return
- /// valid values.
- /// </remarks>
- /// <param name="outlineResolution">
- /// Outline resolution. This is equivalent to ‘face->units_per_EM’ for non-PFR fonts. Optional (parameter can
- /// be NULL).
- /// </param>
- /// <param name="metricsResolution">
- /// Metrics resolution. This is equivalent to ‘outline_resolution’ for non-PFR fonts. Optional (parameter can
- /// be NULL).
- /// </param>
- /// <param name="metricsXScale">
- /// A 16.16 fixed-point number used to scale distance expressed in metrics units to device sub-pixels. This is
- /// equivalent to ‘face->size->x_scale’, but for metrics only. Optional (parameter can be NULL).
- /// </param>
- /// <param name="metricsYScale">
- /// Same as ‘ametrics_x_scale’ but for the vertical direction. optional (parameter can be NULL).
- /// </param>
- [CLSCompliant(false)]
- public void GetPfrMetrics(out uint outlineResolution, out uint metricsResolution, out int metricsXScale, out int metricsYScale)
- {
- Error err = FT.FT_Get_PFR_Metrics(Reference, out outlineResolution, out metricsResolution, out metricsXScale, out metricsYScale);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Return the kerning pair corresponding to two glyphs in a PFR face. The distance is expressed in metrics
- /// units, unlike the result of <see cref="GetKerning"/>.
- /// </summary>
- /// <remarks><para>
- /// This function always return distances in original PFR metrics units. This is unlike
- /// <see cref="GetKerning"/> with the <see cref="KerningMode.Unscaled"/> mode, which always returns
- /// distances converted to outline units.
- /// </para><para>
- /// You can use the value of the ‘x_scale’ and ‘y_scale’ parameters returned by <see cref="GetPfrMetrics"/> to
- /// scale these to device sub-pixels.
- /// </para></remarks>
- /// <param name="left">Index of the left glyph.</param>
- /// <param name="right">Index of the right glyph.</param>
- /// <returns>A kerning vector.</returns>
- [CLSCompliant(false)]
- public FTVector GetPfrKerning(uint left, uint right)
- {
- FTVector vector;
- Error err = FT.FT_Get_PFR_Kerning(Reference, left, right, out vector);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return vector;
- }
- /// <summary>
- /// Return a given glyph advance, expressed in original metrics units, from a PFR font.
- /// </summary>
- /// <remarks>
- /// You can use the ‘x_scale’ or ‘y_scale’ results of <see cref="GetPfrMetrics"/> to convert the advance to
- /// device sub-pixels (i.e., 1/64th of pixels).
- /// </remarks>
- /// <param name="glyphIndex">The glyph index.</param>
- /// <returns>The glyph advance in metrics units.</returns>
- [CLSCompliant(false)]
- public int GetPfrAdvance(uint glyphIndex)
- {
- int advance;
- Error err = FT.FT_Get_PFR_Advance(Reference, glyphIndex, out advance);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return advance;
- }
- #endregion
- #region Windows FNT Files
- /// <summary>
- /// Retrieve a Windows FNT font info header.
- /// </summary>
- /// <remarks>
- /// This function only works with Windows FNT faces, returning an error otherwise.
- /// </remarks>
- /// <returns>The WinFNT header.</returns>
- public Fnt.Header GetWinFntHeader()
- {
- IntPtr headerRef;
- Error err = FT.FT_Get_WinFNT_Header(Reference, out headerRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return new Fnt.Header(headerRef);
- }
- #endregion
- #region Font Formats
- /// <summary>
- /// Return a string describing the format of a given face, using values which can be used as an X11
- /// FONT_PROPERTY. Possible values are ‘TrueType’, ‘Type 1’, ‘BDF’, ‘PCF’, ‘Type 42’, ‘CID Type 1’, ‘CFF’,
- /// ‘PFR’, and ‘Windows FNT’.
- /// </summary>
- /// <returns>Font format string. NULL in case of error.</returns>
- public string GetX11FontFormat()
- {
- return Marshal.PtrToStringAnsi(FT.FT_Get_X11_Font_Format(Reference));
- }
- #endregion
- #region Gasp Table
- /// <summary>
- /// Read the ‘gasp’ table from a TrueType or OpenType font file and return the entry corresponding to a given
- /// character pixel size.
- /// </summary>
- /// <param name="ppem">The vertical character pixel size.</param>
- /// <returns>
- /// Bit flags (see <see cref="Gasp"/>), or <see cref="Gasp.NoTable"/> if there is no ‘gasp’ table in the face.
- /// </returns>
- [CLSCompliant(false)]
- public Gasp GetGasp(uint ppem)
- {
- return FT.FT_Get_Gasp(Reference, ppem);
- }
- #endregion
- #region Quick retrieval of advance values
- /// <summary>
- /// Retrieve the advance value of a given glyph outline in a <see cref="Face"/>. By default, the unhinted
- /// advance is returned in font units.
- /// </summary>
- /// <remarks><para>
- /// This function may fail if you use <see cref="LoadFlags.AdvanceFlagFastOnly"/> and if the corresponding font
- /// backend doesn't have a quick way to retrieve the advances.
- /// </para><para>
- /// A scaled advance is returned in 16.16 format but isn't transformed by the affine transformation specified
- /// by <see cref="SetTransform"/>.
- /// </para></remarks>
- /// <param name="glyphIndex">The glyph index.</param>
- /// <param name="flags">
- /// A set of bit flags similar to those used when calling <see cref="LoadGlyph"/>, used to determine what kind
- /// of advances you need.
- /// </param>
- /// <returns><para>
- /// The advance value, in either font units or 16.16 format.
- /// </para><para>
- /// If <see cref="LoadFlags.VerticalLayout"/> is set, this is the vertical advance corresponding to a vertical
- /// layout. Otherwise, it is the horizontal advance in a horizontal layout.
- /// </para></returns>
- [CLSCompliant(false)]
- public int GetAdvance(uint glyphIndex, LoadFlags flags)
- {
- int padvance;
- Error err = FT.FT_Get_Advance(Reference, glyphIndex, flags, out padvance);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return padvance;
- }
- /// <summary>
- /// Retrieve the advance values of several glyph outlines in an
- /// <see cref="Face"/>. By default, the unhinted advances are returned
- /// in font units.
- /// </summary>
- /// <remarks><para>
- /// This function may fail if you use
- /// <see cref="LoadFlags.AdvanceFlagFastOnly"/> and if the
- /// corresponding font backend doesn't have a quick way to retrieve the
- /// advances.
- /// </para><para>
- /// Scaled advances are returned in 16.16 format but aren't transformed
- /// by the affine transformation specified by
- /// <see cref="SetTransform"/>.
- /// </para></remarks>
- /// <param name="start">The first glyph index.</param>
- /// <param name="count">The number of advance values you want to retrieve.</param>
- /// <param name="flags">A set of bit flags similar to those used when calling <see cref="LoadGlyph"/>.</param>
- /// <returns><para>The advances, in either font units or 16.16 format. This array must contain at least ‘count’ elements.
- /// </para><para>
- /// If <see cref="LoadFlags.VerticalLayout"/> is set, these are the vertical advances corresponding to a vertical layout. Otherwise, they are the horizontal advances in a horizontal layout.</para></returns>
- [CLSCompliant(false)]
- public unsafe int[] GetAdvances(uint start, uint count, LoadFlags flags)
- {
- IntPtr advPtr;
- Error err = FT.FT_Get_Advances(Reference, start, count, flags, out advPtr);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- //create a new array and copy the data from the pointer over
- int[] advances = new int[count];
- int* ptr = (int*)advPtr;
- for (int i = 0; i < count; i++)
- advances[i] = ptr[i];
- return advances;
- }
- #endregion
- #region OpenType Validation
- /// <summary>
- /// Validate various OpenType tables to assure that all offsets and indices are valid. The idea is that a
- /// higher-level library which actually does the text layout can access those tables without error checking
- /// (which can be quite time consuming).
- /// </summary>
- /// <remarks><para>
- /// This function only works with OpenType fonts, returning an error otherwise.
- /// </para><para>
- /// After use, the application should deallocate the five tables with <see cref="OpenTypeFree"/>. A NULL value
- /// indicates that the table either doesn't exist in the font, or the application hasn't asked for validation.
- /// </para></remarks>
- /// <param name="flags">A bit field which specifies the tables to be validated.</param>
- /// <param name="baseTable">A pointer to the BASE table.</param>
- /// <param name="gdefTable">A pointer to the GDEF table.</param>
- /// <param name="gposTable">A pointer to the GPOS table.</param>
- /// <param name="gsubTable">A pointer to the GSUB table.</param>
- /// <param name="jstfTable">A pointer to the JSTF table.</param>
- [CLSCompliant(false)]
- public void OpenTypeValidate(OpenTypeValidationFlags flags, out IntPtr baseTable, out IntPtr gdefTable, out IntPtr gposTable, out IntPtr gsubTable, out IntPtr jstfTable)
- {
- Error err = FT.FT_OpenType_Validate(Reference, flags, out baseTable, out gdefTable, out gposTable, out gsubTable, out jstfTable);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
- /// <summary>
- /// Free the buffer allocated by OpenType validator.
- /// </summary>
- /// <remarks>
- /// This function must be used to free the buffer allocated by <see cref="OpenTypeValidate"/> only.
- /// </remarks>
- /// <param name="table">The pointer to the buffer that is allocated by <see cref="OpenTypeValidate"/>.</param>
- public void OpenTypeFree(IntPtr table)
- {
- FT.FT_OpenType_Free(Reference, table);
- }
- #endregion
- #region TrueTypeGX/AAT Validation
- /// <summary>
- /// Validate various TrueTypeGX tables to assure that all offsets and indices are valid. The idea is that a
- /// higher-level library which actually does the text layout can access those tables without error checking
- /// (which can be quite time consuming).
- /// </summary>
- /// <remarks><para>
- /// This function only works with TrueTypeGX fonts, returning an error otherwise.
- /// </para><para>
- /// After use, the application should deallocate the buffers pointed to by each ‘tables’ element, by calling
- /// <see cref="TrueTypeGXFree"/>. A NULL value indicates that the table either doesn't exist in the font, the
- /// application hasn't asked for validation, or the validator doesn't have the ability to validate the sfnt
- /// table.
- /// </para></remarks>
- /// <param name="flags">A bit field which specifies the tables to be validated.</param>
- /// <param name="tables">
- /// The array where all validated sfnt tables are stored. The array itself must be allocated by a client.
- /// </param>
- /// <param name="tableLength">
- /// The size of the ‘tables’ array. Normally, FT_VALIDATE_GX_LENGTH should be passed.
- /// </param>
- [CLSCompliant(false)]
- public void TrueTypeGXValidate(TrueTypeValidationFlags flags, byte[][] tables, uint tableLength)
- {
- FT.FT_TrueTypeGX_Validate(Reference, flags, tables, tableLength);
- }
- /// <summary>
- /// Free the buffer allocated by TrueTypeGX validator.
- /// </summary>
- /// <remarks>
- /// This function must be used to free the buffer allocated by <see cref="TrueTypeGXValidate"/> only.
- /// </remarks>
- /// <param name="table">The pointer to the buffer allocated by <see cref="TrueTypeGXValidate"/>.</param>
- public void TrueTypeGXFree(IntPtr table)
- {
- FT.FT_TrueTypeGX_Free(Reference, table);
- }
- /// <summary><para>
- /// Validate classic (16-bit format) kern table to assure that the offsets and indices are valid. The idea is
- /// that a higher-level library which actually does the text layout can access those tables without error
- /// checking (which can be quite time consuming).
- /// </para><para>
- /// The ‘kern’ table validator in <see cref="TrueTypeGXValidate"/> deals with both the new 32-bit format and
- /// the classic 16-bit format, while <see cref="ClassicKernValidate"/> only supports the classic 16-bit format.
- /// </para></summary>
- /// <remarks>
- /// After use, the application should deallocate the buffers pointed to by ‘ckern_table’, by calling
- /// <see cref="ClassicKernFree"/>. A NULL value indicates that the table doesn't exist in the font.
- /// </remarks>
- /// <param name="flags">A bit field which specifies the dialect to be validated.</param>
- /// <returns>A pointer to the kern table.</returns>
- [CLSCompliant(false)]
- public IntPtr ClassicKernValidate(ClassicKernValidationFlags flags)
- {
- IntPtr ckernRef;
- FT.FT_ClassicKern_Validate(Reference, flags, out ckernRef);
- return ckernRef;
- }
- /// <summary>
- /// Free the buffer allocated by classic Kern validator.
- /// </summary>
- /// <remarks>
- /// This function must be used to free the buffer allocated by <see cref="ClassicKernValidate"/> only.
- /// </remarks>
- /// <param name="table">
- /// The pointer to the buffer that is allocated by <see cref="ClassicKernValidate"/>.
- /// </param>
- public void ClassicKernFree(IntPtr table)
- {
- FT.FT_ClassicKern_Free(Reference, table);
- }
- #endregion
- /// <summary>
- /// Disposes the Face.
- /// </summary>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- internal void AddChildSize(FTSize child)
- {
- childSizes.Add(child);
- }
- internal void RemoveChildSize(FTSize child)
- {
- childSizes.Remove(child);
- }
- private void Dispose(bool disposing)
- {
- if (!disposed)
- {
- disposed = true;
-
- foreach (FTSize s in childSizes)
- s.Dispose();
- childSizes.Clear();
- Error err = FT.FT_Done_Face(reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- // removes itself from the parent Library, with a check to prevent this from happening when Library is
- // being disposed (Library disposes all it's children with a foreach loop, this causes an
- // InvalidOperationException for modifying a collection during enumeration)
- if (!parentLibrary.IsDisposed)
- parentLibrary.RemoveChildFace(this);
- reference = IntPtr.Zero;
- rec = null;
- }
- }
- #endregion
- }
- }
|