Пример #1
0
 private void Load(Blob blob, uint index = 0)
 {
     Face = new Face(blob, index);
     if (Face.Handle != IntPtr.Zero)
     {
         Font = new HarfBuzzSharp.Font(Face);
         Font.SetFunctionsOpenType();
     }
 }
        public GlyphTypefaceImpl(Typeface typeface)
        {
            DWFont = Direct2D1FontCollectionCache.GetFont(typeface);

            FontFace = new FontFace(DWFont).QueryInterface <FontFace1>();

            Face = new Face(GetTable);

            Font = new HarfBuzzSharp.Font(Face);

            Font.SetFunctionsOpenType();

            Font.GetScale(out var xScale, out _);

            DesignEmHeight = (short)xScale;

            if (!Font.TryGetHorizontalFontExtents(out var fontExtents))
            {
                Font.TryGetVerticalFontExtents(out fontExtents);
            }

            Ascent = -fontExtents.Ascender;

            Descent = -fontExtents.Descender;

            LineGap = fontExtents.LineGap;

            if (Font.OpenTypeMetrics.TryGetPosition(OpenTypeMetricsTag.UnderlineOffset, out var underlinePosition))
            {
                UnderlinePosition = underlinePosition;
            }

            if (Font.OpenTypeMetrics.TryGetPosition(OpenTypeMetricsTag.UnderlineSize, out var underlineThickness))
            {
                UnderlineThickness = underlineThickness;
            }

            if (Font.OpenTypeMetrics.TryGetPosition(OpenTypeMetricsTag.StrikeoutOffset, out var strikethroughPosition))
            {
                StrikethroughPosition = strikethroughPosition;
            }

            if (Font.OpenTypeMetrics.TryGetPosition(OpenTypeMetricsTag.StrikeoutSize, out var strikethroughThickness))
            {
                StrikethroughThickness = strikethroughThickness;
            }

            IsFixedPitch = FontFace.IsMonospacedFont;
        }
Пример #3
0
        public TypefaceTextShaper(SKTypeface typeface)
        {
            Typeface = typeface ?? throw new ArgumentNullException(nameof(typeface));

            int index;

            using (var blob = Typeface.OpenStream(out index).ToHarfBuzzBlob())
                using (var face = new Face(blob, index))
                {
                    face.Index      = index;
                    face.UnitsPerEm = Typeface.UnitsPerEm;

                    font = new HarfBuzzSharp.Font(face);
                    font.SetScale(FONT_SIZE_SCALE, FONT_SIZE_SCALE);

                    font.SetFunctionsOpenType();
                }
        }
Пример #4
0
        /// <summary>
        /// Constructs a new TextShaper
        /// </summary>
        /// <param name="typeface">The typeface of this shaper</param>
        private TextShaper(SKTypeface typeface)
        {
            // Load the typeface stream to a HarfBuzz font
            int index;

            using (var blob = typeface.OpenStream(out index).ToHarfBuzzBlob())
                using (var face = new Face(blob, (uint)index))
                {
                    face.UnitsPerEm = (uint)typeface.UnitsPerEm;

                    _font = new HarfBuzzSharp.Font(face);
                    _font.SetScale(overScale, overScale);
                    _font.SetFunctionsOpenType();
                }

            // Get font metrics for this typeface
            using (var paint = new SKPaint())
            {
                paint.Typeface = typeface;
                paint.TextSize = overScale;
                _fontMetrics   = paint.FontMetrics;
            }
        }
Пример #5
0
        /// <summary>
        /// Constructs a new TextShaper
        /// </summary>
        /// <param name="typeface">The typeface of this shaper</param>
        private TextShaper(SKTypeface typeface)
        {
            // Store typeface
            _typeface = typeface;

            // Load the typeface stream to a HarfBuzz font
            int index;

            using (var blob = GetHarfBuzzBlob(typeface.OpenStream(out index)))
                using (var face = new Face(blob, (uint)index))
                {
                    face.UnitsPerEm = typeface.UnitsPerEm;

                    _font = new HarfBuzzSharp.Font(face);
                    _font.SetScale(overScale, overScale);
                    _font.SetFunctionsOpenType();
                }

            // Get font metrics for this typeface
            using (var paint = new SKPaint())
            {
                paint.Typeface = typeface;
                paint.TextSize = overScale;
                _fontMetrics   = paint.FontMetrics;

                // This is a temporary hack until SkiaSharp exposes
                // a way to check if a font is fixed pitch.  For now
                // we just measure and `i` and a `w` and see if they're
                // the same width.
                float[] widths = paint.GetGlyphWidths("iw", out var rects);
                _isFixedPitch = widths != null && widths.Length > 1 && widths[0] == widths[1];
                if (_isFixedPitch)
                {
                    _fixedCharacterWidth = widths[0];
                }
            }
        }