public void TestLoadIntoInvalidTarget() { var loadable = new DelayedTestBoxAsync(); var loadTarget = new LoadTarget(loadable); Assert.Throws <InvalidOperationException>(() => loadTarget.PerformAsyncLoad()); }
public FT_Error LoadGlyph(uint glyph_index, LoadFlags flags, LoadTarget target) { if (Form == LongForm.Long4) { return(FT_Load_Glyph_4(mHandle, glyph_index, ((Int32)flags | (Int32)target))); } else { return(FT_Load_Glyph_8(mHandle, glyph_index, ((Int32)flags | (Int32)target))); } }
public void TestSingleAsyncAdd() { var loadable = new DelayedTestBoxAsync(); var loadTarget = new LoadTarget(loadable); Assert.DoesNotThrow(() => { runGameWithLogic(g => { g.Add(loadTarget); loadTarget.PerformAsyncLoad(); }, g => loadable.Parent == loadTarget); }); }
public void TestDoubleAsyncAddFails() { Assert.Throws <InvalidOperationException>(() => { runGameWithLogic(g => { var loadable = new DelayedTestBoxAsync(); var loadTarget = new LoadTarget(loadable); g.Add(loadTarget); loadTarget.PerformAsyncLoad(); loadTarget.PerformAsyncLoad(); }); }); }
public void TestTargetDisposedDuringAsyncLoad() { Assert.Throws <ObjectDisposedException>(() => { runGameWithLogic(g => { var loadable = new DelayedTestBoxAsync(); var loadTarget = new LoadTarget(loadable); g.Add(loadTarget); loadTarget.PerformAsyncLoad(); while (loadable.LoadState < LoadState.Loading) { Thread.Sleep(1); } g.Dispose(); }); }); }
public void TestDisposeAfterLoad() { Assert.DoesNotThrow(() => { var loadTarget = new LoadTarget(new DelayedTestBoxAsync()); bool allowDispose = false; bool disposeTriggered = false; bool updatedAfterDispose = false; runGameWithLogic(g => { g.Add(loadTarget); loadTarget.PerformAsyncLoad().ContinueWith(t => allowDispose = true); }, g => { // The following code is done here for a very specific reason, but can occur naturally in normal use // This delegate is essentially the first item in the game's scheduler, so it will always run PRIOR to the async callback if (disposeTriggered) { updatedAfterDispose = true; } if (allowDispose) { // Async load has complete, the callback has been scheduled but NOT run yet // Dispose the parent container - this is done by clearing the game g.Clear(true); disposeTriggered = true; } // After disposing the parent, one update loop is required return(updatedAfterDispose); }); }); }
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); }
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); }
public bool RastTest(int resX, int resY, int[] arrPointSizes, float stretchX, float stretchY, float rotation, float skew, float[,] matrix, bool setBW, bool setGrayscale, bool setCleartype, uint CTFlags, RastTestErrorDelegate pRastTestErrorDelegate, UpdateProgressDelegate pUpdateProgressDelegate, int numGlyphs) { int count_sets = 0; LoadFlags lf = LoadFlags.Default; LoadTarget lt = LoadTarget.Normal; if (setBW) { lf = LoadFlags.Default | LoadFlags.NoAutohint | LoadFlags.Monochrome | LoadFlags.ComputeMetrics; lt = LoadTarget.Mono; _lib.PropertySet("truetype", "interpreter-version", 35); count_sets++; } if (setGrayscale) { lf = LoadFlags.Default | LoadFlags.NoAutohint | LoadFlags.ComputeMetrics; lt = LoadTarget.Normal; _lib.PropertySet("truetype", "interpreter-version", 35); count_sets++; } if (setCleartype) { lf = LoadFlags.Default | LoadFlags.NoAutohint | LoadFlags.ComputeMetrics; lt = LoadTarget.Lcd; _lib.PropertySet("truetype", "interpreter-version", 40); count_sets++; } if (count_sets != 1) { throw new ArgumentOutOfRangeException("Only one of BW/Grayscale/Cleartype should be set"); } try { TT_Diagnostics_Unset(); } catch (Exception e) { throw new NotImplementedException("UnImplemented in this version of Freetype: " + FTVersion); }; FTMatrix fmatrix = new FTMatrix(new Fixed16Dot16(matrix[0, 0] * stretchX), new Fixed16Dot16(matrix[0, 1] * stretchX), new Fixed16Dot16(matrix[1, 0] * stretchY), new Fixed16Dot16(matrix[1, 1] * stretchY)); FTVector fdelta = new FTVector(new Fixed16Dot16(matrix[0, 2] * stretchX), new Fixed16Dot16(matrix[1, 2] * stretchY)); /* matrix[2,0] = matrix[2,1] = 0, matrix[2,2] =1, not used */ FTMatrix mskew = new FTMatrix(new Fixed16Dot16(1), new Fixed16Dot16(0), (new Fixed16Dot16(skew)).Tan(), new Fixed16Dot16(1)); FTMatrix.Multiply(ref mskew, ref fmatrix); fdelta.Transform(mskew); FTVector rot_row1 = new FTVector(new Fixed16Dot16(1), new Fixed16Dot16(0)); FTVector rot_row2 = new FTVector(new Fixed16Dot16(1), new Fixed16Dot16(0)); rot_row1.Rotate(new Fixed16Dot16(rotation)); rot_row2.Rotate(new Fixed16Dot16(rotation + 90)); FTMatrix mrot = new FTMatrix(rot_row1, rot_row2); FTMatrix.Multiply(ref mrot, ref fmatrix); fdelta.Rotate(new Fixed16Dot16(-rotation)); for (int i = 0; i < arrPointSizes.Length; i++) { if (m_UserCancelledTest) { return(true); } pUpdateProgressDelegate("Processing Size " + arrPointSizes[i]); try{ _face.SetCharSize(new Fixed26Dot6(arrPointSizes[i]), new Fixed26Dot6(arrPointSizes[i]), (uint)resX, (uint)resY); } catch (FreeTypeException e) { if (e.Error == Error.InvalidPixelSize) { pRastTestErrorDelegate("_rast_W_FT_InvalidPixelSize", "Setting unsupported size " + arrPointSizes[i] + " for fixed-size font."); m_RastErrorCount += 1; continue; } else { throw; } } _face.SetTransform(fmatrix, fdelta); for (uint ig = 0; ig < numGlyphs; ig++) { diagnostics_Function diagnostics = (message, opcode, range_base, is_composite, IP, callTop, opc, start) => { string sDetails = "Size " + arrPointSizes[i] + ", " + opcode; switch (range_base) { case 3: if (is_composite != 0) { sDetails += ", Composite Glyph ID " + ig; } else { sDetails += ", Glyph ID " + ig; } break; case 1: /* font */ case 2: /* cvt */ // ? sDetails += ", Pre-Program"; break; default: /* none */ sDetails += ", Unknown?"; // ? break; } sDetails += ", At ByteOffset " + IP; if (callTop > 0) { sDetails += ", In function " + opc + " offsetted by " + (IP - start); } pRastTestErrorDelegate(message, sDetails); m_RastErrorCount += 1; return(0); // Not used currently. }; TT_Diagnostics_Set(diagnostics); try{ _face.LoadGlyph(ig, lf, lt); } catch (Exception ee) { if (ee is FreeTypeException) { FreeTypeException e = (FreeTypeException)ee; if (e.Error == Error.InvalidOutline) { pRastTestErrorDelegate("_rast_W_FT_InvalidOutline", "Invalid Outline in Glyph " + ig); m_RastErrorCount += 1; continue; } if (e.Error == Error.InvalidArgument) { pRastTestErrorDelegate("_rast_W_FT_InvalidArgument", "Invalid Argument in Glyph " + ig); m_RastErrorCount += 1; continue; } if (e.Error == Error.InvalidSizeHandle) { pRastTestErrorDelegate("_rast_W_FT_InvalidSizeHandle", "Invalid Metrics for Glyph " + ig + " at size " + arrPointSizes[i]); m_RastErrorCount += 1; continue; } } pRastTestErrorDelegate("_rast_I_FT_Error_Supplymentary_Info", "Glyph " + ig + " at size " + arrPointSizes[i]); throw; } TT_Diagnostics_Unset(); } } return(true); }
public TapestryLoadOmniusException(string message, LoadTarget target, Exception innerException) : base(message, innerException) { Target = target; }
public static bool LoadGlyph(ref Texture_Font_T font, char codepoint) { int i; int x; int y; Glyph glyph; GlyphSlot glyphSlot; FTBitmap fTBitmap; uint glyphindex; Texture_Glyph_T glyph_T; int glyphtop = 0; int glyphleft = 0; Region region; int missed = 0; //check glyph has not already been loaded if (FindGlyph(ref font, codepoint, out glyph_T)) { return(true); } // handle null codepoint if (codepoint == '\0') { region = Atlas.Atlas.GetRegion(ref font.Atlas, 5, 5); glyph_T = InitGlyph(); byte[] data = new byte[4 * 4 * 3] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; if (region.X < 0) { //throw new Exception("texture atlas is full!"); return(false); } Atlas.Atlas.SetRegion(ref font.Atlas, region.X, region.Y, 4, 4, data, 0); glyph_T.Codepoint = -1; glyph_T.S01 = (region.X + 2) / (float)font.Atlas.Width; glyph_T.T01 = (region.Y + 2) / (float)font.Atlas.Height; glyph_T.S11 = (region.X + 3) / (float)font.Atlas.Width; glyph_T.T11 = (region.Y + 3) / (float)font.Atlas.Height; font.Glyphs.Add(glyph_T); return(true); } LoadFlags flags = 0; LoadTarget target = 0; glyphindex = face.GetCharIndex((uint)char.ConvertToUtf32(codepoint.ToString(), 0)); if (font.Rendermode != RenderMode.RENDER_NORMAL && font.Rendermode != RenderMode.RENDER_SIGNED_DISTANCE_FIELD) { flags |= LoadFlags.NoBitmap; } else { flags |= LoadFlags.Render; } if (!font.Hinting) { flags |= LoadFlags.NoHinting | LoadFlags.NoAutohint; } else { flags |= LoadFlags.ForceAutohint; } if (font.Atlas.Depth == 3) { library.SetLcdFilter(LcdFilter.Light); target |= LoadTarget.Lcd; if (font.Filtering) { library.SetLcdFilterWeights(font.Lcd_filter_weights); } } else if (HRES == 1) { target |= LoadTarget.Light; } face.LoadGlyph(glyphindex, flags, target); if (font.Rendermode == RenderMode.RENDER_NORMAL || font.Rendermode == RenderMode.RENDER_SIGNED_DISTANCE_FIELD) { glyphSlot = face.Glyph; fTBitmap = glyphSlot.Bitmap; glyphtop = glyphSlot.BitmapTop; glyphleft = glyphSlot.BitmapLeft; } else { Stroker stroker = new Stroker(library); BitmapGlyph bitmapGlyph; stroker.Set((int)(font.Outlinethickness * HRES), StrokerLineCap.Round, StrokerLineJoin.Round, 0); glyph = face.Glyph.GetGlyph(); if (font.Rendermode == RenderMode.RENDER_OUTLINE_EDGE) { glyph.Stroke(stroker, true); } else if (font.Rendermode == RenderMode.RENDER_OUTLINE_NEGATIVE) { glyph.StrokeBorder(stroker, true, true); } else if (font.Rendermode == RenderMode.RENDER_OUTLINE_POSITIVE) { glyph.StrokeBorder(stroker, false, true); } if (font.Atlas.Depth == 1) { glyph.ToBitmap(SharpFont.RenderMode.Normal, new FTVector26Dot6(0, 0), true); } else { glyph.ToBitmap(SharpFont.RenderMode.Lcd, new FTVector26Dot6(0, 0), true); } bitmapGlyph = glyph.ToBitmapGlyph(); fTBitmap = bitmapGlyph.Bitmap; glyphtop = bitmapGlyph.Top; glyphleft = bitmapGlyph.Left; stroker.Dispose(); } Padding padding = new Padding(0, 1, 0, 1); if (font.Rendermode == RenderMode.RENDER_SIGNED_DISTANCE_FIELD) { padding.Top = 1; padding.Left = 1; } if (font.Padding != 0) { padding.Left += font.Padding; padding.Right += font.Padding; padding.Top += font.Padding; padding.Bottom += font.Padding; } int width = (fTBitmap.Width / font.Atlas.Depth) + padding.Left + padding.Right; int height = fTBitmap.Rows + padding.Top + padding.Bottom; region = Atlas.Atlas.GetRegion(ref font.Atlas, width, height); if (region.X < 0) { //throw new exception("texture atlas full"); return(false); } byte[] data = new byte[width * height * font.Atlas.Depth]; data = fTBitmap.BufferData; if (font.Rendermode == RenderMode.RENDER_SIGNED_DISTANCE_FIELD) { // todo ? where is make distance map comming from throw new NotImplementedException(); } Atlas.Atlas.SetRegion(ref font.Atlas, region.X, region.Y, width, height, data, width * font.Atlas.Depth); glyph_T = InitGlyph(); glyph_T.Codepoint = (uint)char.ConvertToUtf32(codepoint.ToString(), 0); glyph_T.Width = (uint)width; glyph_T.Height = (uint)height; glyph_T.RenderMode = font.Rendermode; glyph_T.Outlinethickness = font.Outlinethickness; glyph_T.OffsetX = glyphleft; glyph_T.OffsetY = glyphtop; glyph_T.S01 = region.X / (float)font.Atlas.Width; glyph_T.T01 = region.Y / (float)font.Atlas.Height; glyph_T.S11 = (region.X + width) / (float)font.Atlas.Width; glyph_T.T11 = (region.Y + height) / (float)font.Atlas.Height; face.LoadGlyph(glyphindex, LoadFlags.Render | LoadFlags.NoHinting, target); glyphSlot = face.Glyph; glyph_T.Advancex = glyphSlot.Advance.X.ToSingle(); glyph_T.Advancey = glyphSlot.Advance.Y.ToSingle(); font.Glyphs.Add(glyph_T); if (font.Rendermode != RenderMode.RENDER_NORMAL && font.Rendermode != RenderMode.RENDER_SIGNED_DISTANCE_FIELD) { glyph.Dispose(); } GenerateKerning(ref font); return(true); }
public void LoadGlyph(uint glyphIndex, LoadFlags loadFlags, LoadTarget loadTarget) => FreeType.ThrowIfNotOk(FreeType.FT_Load_Glyph(Handle, glyphIndex, (LoadFlags)((int)loadFlags | (int)loadTarget)));
public void LoadCharacter(uint charCode, LoadFlags loadFlags, LoadTarget loadTarget) => FreeType.ThrowIfNotOk(FreeType.FT_Load_Char(Handle, charCode, (LoadFlags)((int)loadFlags | (int)loadTarget)));