/// <summary> /// Initializes this reader to iterate over the supplied glyph. /// </summary> /// <param name="openType">The font containing the glyph.</param> /// <param name="pixelSize">The size in pixels of the font.</param> /// <param name="glyphIndex">The index of the glyph in <paramref name="openType"/>.</param> /// <returns><c>true</c> if the glyph can be read.</returns> public bool Setup(OpenType openType, double pixelSize, int glyphIndex) { currentDecoder = (openType.GetGlyphOutlineKind()) switch { GlyphOutlineKind.Ttf => trueTypeGlyphDecoder, GlyphOutlineKind.Cff => cffGlyphDecoder, _ => throw new InvalidOperationException("Glyph outline kind: " + openType.GetGlyphOutlineKind()), }; return(currentDecoder.Setup(openType, pixelSize, (uint)glyphIndex)); }
internal override bool Setup(OpenType openType, double pixelSize, uint glyphIndex) { Reset(); if (openType.GetGlyphOutlineKind() != GlyphOutlineKind.Cff) { throw new ArgumentException(nameof(openType)); } this.openType = openType; globalSubrs = openType.GetGlobalSubrs(); subrs = openType.GetGlyphSubrs(glyphIndex); charString = openType.GetCharString(glyphIndex); Scale = pixelSize / openType.GetUnitsPerEm(); bool first = true; XMin = 0; XMax = 0; YMin = 0; YMax = 0; while (Move()) { if (first) { first = false; XMin = X; YMin = Y; XMax = X; YMax = Y; } else { if (X < XMin) { XMin = X; } else if (X > XMax) { XMax = X; } if (Y < YMin) { YMin = Y; } else if (Y > YMax) { YMax = Y; } } switch (PathCommand) { case PathCommand.MoveTo: break; case PathCommand.LineTo: break; case PathCommand.CubicBezierTo: if (Cx1 < XMin) { XMin = Cx1; } else if (Cx1 > XMax) { XMax = Cx1; } if (Cy1 < YMin) { YMin = Cy1; } else if (Cy1 > YMax) { YMax = Cy1; } goto case PathCommand.QuadraticBezierTo; case PathCommand.QuadraticBezierTo: if (Cx < XMin) { XMin = Cx; } else if (Cx > XMax) { XMax = Cx; } if (Cy < YMin) { YMin = Cy; } else if (Cy > YMax) { YMax = Cy; } break; } } Reset(); return(XMin != 0 || XMax != 0); }