Ejemplo n.º 1
0
 public bool TryGetGlyphRect(int glyphIndex, Vector2 scale, Point oversample, Vector2 shift, out Rectangle rectangle)
 {
     if (TT.GetGlyphBitmapBoxSubpixel(
             FontInfo, glyphIndex, scale * oversample, shift, out TT.IntRect rect))
     {
         rectangle = new Rectangle(rect.X, rect.Y, rect.W, rect.H);
         return(true);
     }
     rectangle = default;
     return(false);
 }
Ejemplo n.º 2
0
 public bool GetGlyphBox(int glyphIndex, out RectangleF glyphBox)
 {
     if (TT.GetGlyphBox(FontInfo, glyphIndex, out var rectBox))
     {
         glyphBox = new RectangleF(
             rectBox.X, rectBox.Y,
             rectBox.W, rectBox.H);
         return(true);
     }
     glyphBox = default;
     return(false);
 }
Ejemplo n.º 3
0
        public static RectangleF GetDrawRectangle(Rectangle rectangle, Point oversample, Vector2 shift)
        {
            int        w             = rectangle.Width + oversample.X - 1;
            int        h             = rectangle.Height + oversample.Y - 1;
            float      sub_x         = TT.OversampleShift(oversample.X);
            float      sub_y         = TT.OversampleShift(oversample.Y);
            float      drawX         = (rectangle.X - shift.X) / oversample.X + sub_x;
            float      drawY         = (rectangle.Y - shift.Y) / oversample.Y + sub_y;
            float      drawW         = w / (float)oversample.X + sub_x;
            float      drawH         = h / (float)oversample.Y + sub_y;
            RectangleF drawRectangle = new (drawX, drawY, drawW, drawH);

            return(drawRectangle);
        }
Ejemplo n.º 4
0
        public bool TryGetGlyphBitmap(
            int glyphIndex, Vector2 scale, Point oversample, Vector2 shift,
            [MaybeNullWhen(false)] out Image <Alpha8> image,
            out RectangleF drawRectangle)
        {
            if (!TryGetGlyphRect(glyphIndex, scale, oversample, shift, out Rectangle rect))
            {
                image         = default;
                drawRectangle = default;
                return(false);
            }

            int w = rect.Width + oversample.X - 1;
            int h = rect.Height + oversample.Y - 1;

            image = Image <Alpha8> .CreateUninitialized(w, h);

            TT.Bitmap glyphBmp = GetTTBitmap(image, rect.Width, rect.Height);
            TT.MakeGlyphBitmap(
                FontInfo,
                glyphBmp,
                0.35f,
                scale * oversample,
                shift,
                TT.IntPoint.Zero,
                glyphIndex);

            TT.Bitmap filterBmp = GetTTBitmap(image, w, h);
            if (oversample.X > 1)
            {
                TT.HorizontalPrefilter(filterBmp, oversample.X);
            }
            if (oversample.Y > 1)
            {
                TT.VerticalPrefilter(filterBmp, oversample.Y);
            }

            drawRectangle = GetDrawRectangle(rect, oversample, shift);

            return(true);
        }
Ejemplo n.º 5
0
 public float GetScaleByEm(float pixels)
 {
     return(TT.ScaleForMappingEmToPixels(FontInfo, pixels));
 }
Ejemplo n.º 6
0
 public float GetScaleByPixel(float pixelHeight)
 {
     return(TT.ScaleForPixelHeight(FontInfo, pixelHeight));
 }
Ejemplo n.º 7
0
 public int GetGlyphIndex(int codepoint)
 {
     return(TT.FindGlyphIndex(FontInfo, codepoint));
 }
Ejemplo n.º 8
0
 public void GetFontVMetrics(out int ascent, out int descent, out int lineGap)
 {
     TT.GetFontVMetrics(FontInfo, out ascent, out descent, out lineGap);
 }
Ejemplo n.º 9
0
 public void GetGlyphHMetrics(int glyphIndex, out int advanceWidth, out int leftSideBearing)
 {
     TT.GetGlyphHMetrics(FontInfo, glyphIndex, out advanceWidth, out leftSideBearing);
 }
Ejemplo n.º 10
0
 public int?GetGlyphKernAdvance(int glyphIndex1, int glyphIndex2)
 {
     return(TT.GetGlyphKernAdvance(FontInfo, glyphIndex1, glyphIndex2));
 }
Ejemplo n.º 11
0
 public bool GetGlyphRightSideBearing(int glyphIndex, out float rightSideBearing)
 {
     return(TT.GetGlyphRightSideBearing(FontInfo, glyphIndex, out rightSideBearing));
 }
Ejemplo n.º 12
0
 public Font(ReadOnlyMemory <byte> fontData)
 {
     FontInfo = new TT.FontInfo();
     TT.InitFont(FontInfo, fontData);
 }