internal Rect BoundGlyph(uint glyphIndex, StyleSimulations style) { var recip = 1 / (float)FtFace.UnitsPerEM; //var strength = 0.02f; var trm = AdjustGlyphWidth(glyphIndex); var m = new FTMatrix((int)trm.M11 * 65536, (int)trm.M21 * 65536, (int)trm.M12 * 65536, (int)trm.M22 * 65536); var v = new FTVector(Fixed16Dot16.FromDouble(trm.OffsetX * 65536), Fixed16Dot16.FromDouble(trm.OffsetY * 65536)); FtFace.SetCharSize(Fixed26Dot6.FromInt32(FtFace.UnitsPerEM), Fixed26Dot6.FromInt32(FtFace.UnitsPerEM), 72, 72); FtFace.SetTransform(m, v); FtFace.LoadGlyph(glyphIndex, LoadFlags.NoBitmap | LoadFlags.NoHinting, LoadTarget.Normal); /*if (style == StyleSimulations.BoldSimulation) * { * FtFace.Glyph.Outline.Embolden(Fixed26Dot6.FromDouble(strength * FtFace.UnitsPerEM)); * FtFace.Glyph.Outline.Translate((int) (-strength * 0.5 * FtFace.UnitsPerEM), (int) (-strength * 0.5 * FtFace.UnitsPerEM)); * }*/ var box = FtFace.Glyph.GetGlyph().GetCBox(GlyphBBoxMode.Pixels); var rect = new Rect(new Point(box.Left * recip, box.Top * recip), new Point(box.Right * recip, box.Bottom * recip)); if (rect.IsEmpty) { rect = new Rect(new Point(trm.OffsetX, trm.OffsetY), new Point(trm.OffsetX, trm.OffsetY)); } return(rect); }
/// <summary> /// Initializes a <see cref="Face"/>. /// </summary> /// <param name="fontFace">The font face to initialize.</param> /// <param name="fontSize">Font size, in points.</param> /// <param name="rotation">Character rotation, in degrees.</param> private static void InitializeFontFace([NotNull] Face fontFace, float fontSize, float rotation) { fontFace.SetCharSize(0, fontSize, 0, FontDpi); rotation = MathHelper.ToRadians(rotation); var delta = new FTVector(0, 0); var matrix = new FTMatrix(); matrix.XX = (Fixed16Dot16)(float)Math.Cos(rotation); matrix.XY = (Fixed16Dot16)(float)-Math.Sin(rotation); matrix.YX = (Fixed16Dot16)(float)Math.Sin(rotation); matrix.YY = (Fixed16Dot16)(float)Math.Cos(rotation); fontFace.SetTransform(matrix, delta); }
public static bool LoadFace(ref Texture_Font_T font, ref Library library, ref Face face, float size) { library = new Library(); if (library == null) { return(false); } face = new Face(library, font.Filename); if (face == null) { return(false); } face.SelectCharmap(Encoding.Unicode); face.SetCharSize(Fixed26Dot6.FromSingle(size), 0, DPI * HRES, HRES); FTMatrix matrix = new FTMatrix((int)(1.0 / HRES * 0x10000L), (int)(0.0 * 0x10000L), (int)(0.0 * 0x10000L), (int)(1.0 * 0x10000L)); face.SetTransform(matrix); return(true); }
static void Main(string[] args) { //FTLogNormal.Run(); //FTQuantileFunction.RunExample(); //FTMedian.RunExample(); //FTPercentileFunction.RunExample(); //FTMergeSort.RunExample(); //FTANCOVA.RunExample(); FTMatrix.RunExample(); //HiddenMarkovModelUT.Evaluate(); //HiddenMarkovModelUT.Decode(); //HiddenMarkovModelUT.MaximumLikelihoodLearning(); //HiddenMarkvoModelUT.ViterbiLearning(); //HiddenMarkvoModelUT.BaumWelchLearning(); //HiddenMarkovModelUT.BaumWelchLearningContinuous(); //HiddenMarkovClassifierUT.LearnAndPredict(); HiddenMarkovClassifierUT.LearnAndPredictContinuous(); //HiddenMarkovModelUT.Generate(); }
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); }