123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- #region MIT License
- #endregion
- using System;
- using System.Runtime.InteropServices;
- using SharpFont.Internal;
- namespace SharpFont
- {
-
-
-
-
-
-
-
-
- public sealed class Outline : IDisposable
- {
- #region Fields
- private bool disposed;
- private bool duplicate;
- private IntPtr reference;
- private OutlineRec rec;
- private Library parentLibrary;
- private Memory parentMemory;
- #endregion
- #region Constructor
-
-
-
-
-
-
-
-
-
-
-
-
- [CLSCompliant(false)]
- public Outline(Library library, uint pointsCount, int contoursCount)
- {
- IntPtr reference;
- Error err = FT.FT_Outline_New(library.Reference, pointsCount, contoursCount, out reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- parentLibrary = library;
- parentLibrary.AddChildOutline(this);
- }
-
-
-
-
-
-
- [CLSCompliant(false)]
- public Outline(Memory memory, uint pointsCount, int contoursCount)
- {
- IntPtr reference;
- Error err = FT.FT_Outline_New_Internal(memory.Reference, pointsCount, contoursCount, out reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- parentMemory = memory;
- }
- internal Outline(IntPtr reference, Library parent)
- {
- Reference = reference;
- parentLibrary = parent;
- parentLibrary.AddChildOutline(this);
- }
- internal Outline(OutlineRec outlineInt)
- {
- this.rec = outlineInt;
- duplicate = true;
- }
-
-
-
- ~Outline()
- {
- Dispose(false);
- }
- #endregion
- #region Properties
-
-
-
- public bool IsDisposed
- {
- get
- {
- return disposed;
- }
- }
-
-
-
- public short ContoursCount
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("ContoursCount", "Cannot access a disposed object.");
- return rec.n_contours;
- }
- }
-
-
-
- public short PointsCount
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("PointsCount", "Cannot access a disposed object.");
- return rec.n_points;
- }
- }
-
-
-
-
- public FTVector[] Points
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Points", "Cannot access a disposed object.");
- int count = PointsCount;
- if (count == 0)
- return null;
- FTVector[] points = new FTVector[count];
- IntPtr array = rec.points;
- for (int i = 0; i < count; i++)
- {
- points[i] = new FTVector(new IntPtr(array.ToInt64() + IntPtr.Size * i));
- }
- return points;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- public byte[] Tags
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Tags", "Cannot access a disposed object.");
- int count = PointsCount;
- if (count == 0)
- return null;
- byte[] tags = new byte[count];
- IntPtr array = rec.tags;
- for (int i = 0; i < count; i++)
- {
- tags[i] = Marshal.ReadByte(array, IntPtr.Size * i);
- }
- return tags;
- }
- }
-
-
-
-
-
- public short[] Contours
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Contours", "Cannot access a disposed object.");
- int count = ContoursCount;
- if (count == 0)
- return null;
- short[] contours = new short[count];
- IntPtr array = rec.contours;
- for (int i = 0; i < count; i++)
- {
- contours[i] = Marshal.ReadInt16(array, IntPtr.Size * i);
- }
- return contours;
- }
- }
-
-
-
-
-
- public OutlineFlags Flags
- {
- get
- {
- if (disposed)
- throw new ObjectDisposedException("Flags", "Cannot access a disposed object.");
- return rec.flags;
- }
- }
- 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<OutlineRec>(reference);
- }
- }
- #endregion
- #region Methods
- #region Outline Processing
-
-
-
-
-
- public void Copy(Outline target)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- if (target == null)
- throw new ArgumentNullException("target");
- IntPtr targetRef = target.Reference;
- Error err = FT.FT_Outline_Copy(reference, ref targetRef);
- target.Reference = reference;
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
- public void Translate(int offsetX, int offsetY)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- FT.FT_Outline_Translate(reference, offsetX, offsetY);
- }
-
-
-
-
-
-
-
-
- public void Transform(FTMatrix matrix)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- FT.FT_Outline_Transform(reference, ref matrix);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void Embolden(int strength)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- Error err = FT.FT_Outline_Embolden(reference, strength);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
-
-
-
-
-
- public void EmboldenXY(int strengthX, int strengthY)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- Error err = FT.FT_Outline_EmboldenXY(reference, strengthX, strengthY);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
-
-
-
-
- public void Reverse()
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- FT.FT_Outline_Reverse(reference);
- }
-
-
-
- public void Check()
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- Error err = FT.FT_Outline_Check(reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public BBox GetBBox()
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- IntPtr bboxRef;
- Error err = FT.FT_Outline_Get_BBox(reference, out bboxRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- return new BBox(bboxRef);
- }
-
-
-
-
-
-
-
-
-
-
-
- public void Decompose(OutlineFuncs funcInterface, IntPtr user)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- if (funcInterface == null)
- throw new ArgumentNullException("funcInterface");
-
- IntPtr funcInterfaceRef = Marshal.AllocHGlobal(OutlineFuncsRec.SizeInBytes);
- Marshal.WriteIntPtr(funcInterfaceRef, Marshal.GetFunctionPointerForDelegate(funcInterface.MoveFunction));
- Marshal.WriteIntPtr(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "line_to"), Marshal.GetFunctionPointerForDelegate(funcInterface.LineFuction));
- Marshal.WriteIntPtr(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "conic_to"), Marshal.GetFunctionPointerForDelegate(funcInterface.ConicFunction));
- Marshal.WriteIntPtr(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "cubic_to"), Marshal.GetFunctionPointerForDelegate(funcInterface.CubicFunction));
- Marshal.WriteInt32(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "shift"), funcInterface.Shift);
- Marshal.WriteInt32(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "delta"), funcInterface.Delta);
- Error err = FT.FT_Outline_Decompose(reference, funcInterfaceRef, user);
- Marshal.FreeHGlobal(funcInterfaceRef);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
-
-
-
-
-
-
- public BBox GetCBox()
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- IntPtr cboxRef;
- FT.FT_Outline_Get_CBox(reference, out cboxRef);
- return new BBox(cboxRef);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void GetBitmap(FTBitmap bitmap)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- Error err = FT.FT_Outline_Get_Bitmap(parentLibrary.Reference, reference, bitmap.Reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void GetBitmap(Library library, FTBitmap bitmap)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- if (library == null)
- throw new ArgumentNullException("library");
- if (bitmap == null)
- throw new ArgumentNullException("bitmap");
- Error err = FT.FT_Outline_Get_Bitmap(library.Reference, reference, bitmap.Reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void Render(RasterParams parameters)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- if (parameters == null)
- throw new ArgumentNullException("parameters");
- Error err = FT.FT_Outline_Render(parentLibrary.Reference, reference, parameters.Reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void Render(Library library, RasterParams parameters)
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- if (library == null)
- throw new ArgumentNullException("library");
- if (parameters == null)
- throw new ArgumentNullException("parameters");
- Error err = FT.FT_Outline_Render(library.Reference, reference, parameters.Reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
- }
-
-
-
-
-
-
-
-
- public Orientation GetOrientation()
- {
- if (disposed)
- throw new ObjectDisposedException("Outline", "Cannot access a disposed object.");
- return FT.FT_Outline_Get_Orientation(reference);
- }
- #endregion
- #region Glyph Stroker
-
-
-
-
- public StrokerBorder GetInsideBorder()
- {
- return FT.FT_Outline_GetInsideBorder(Reference);
- }
-
-
-
-
- public StrokerBorder GetOutsideBorder()
- {
- return FT.FT_Outline_GetOutsideBorder(Reference);
- }
- #endregion
-
-
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- private void Dispose(bool disposing)
- {
- if (!disposed)
- {
- disposed = true;
- if (!duplicate)
- {
- Error err;
- if (parentLibrary != null)
- err = FT.FT_Outline_Done(parentLibrary.Reference, reference);
- else
- err = FT.FT_Outline_Done_Internal(parentMemory.Reference, reference);
- if (err != Error.Ok)
- throw new FreeTypeException(err);
-
-
-
- if (!parentLibrary.IsDisposed)
- parentLibrary.RemoveChildOutline(this);
- }
- reference = IntPtr.Zero;
- rec = default(OutlineRec);
- }
- }
- #endregion
- }
- }
|