Esempio n. 1
0
        public int Lookup(CodePoint codePoint)
        {
            int index;

            if (table.TryGetValue(codePoint, out index))
            {
                return(index);
            }

            return(-1);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets glyph data for a specific character.
        /// </summary>
        /// <param name="codePoint">The Unicode codepoint for which to retrieve glyph data.</param>
        /// <param name="pixelSize">The desired size of the font, in pixels.</param>
        /// <returns>The glyph data if the font supports the given character; otherwise, <c>null</c>.</returns>
        public Glyph GetGlyph(CodePoint codePoint, float pixelSize)
        {
            var glyphIndex = charMap.Lookup(codePoint);

            if (glyphIndex < 0)
            {
                return(null);
            }

            // set up the control value table
            var scale = ComputeScale(pixelSize);

            // get metrics
            var glyph      = glyphs[glyphIndex];
            var horizontal = hmetrics[glyphIndex];
            var vtemp      = vmetrics?[glyphIndex];

            if (vtemp == null)
            {
                var synth = verticalSynthesized;
                synth.FrontSideBearing -= glyph.MaxY;
                vtemp = synth;
            }
            var vertical = vtemp.GetValueOrDefault();

            // build and transform the glyph
            var points    = new List <PointF>(32);
            var contours  = new List <int>(32);
            var transform = Matrix3x2.CreateScale(scale, -scale);

            //transform.Translation = offset;

            Geometry.ComposeGlyphs(glyphIndex, 0, ref transform, points, contours, glyphs);

            // add phantom points; these are used to define the extents of the glyph,
            // and can be modified by hinting instructions
            var pp1 = new Point(glyph.MinX - horizontal.FrontSideBearing, 0);
            var pp2 = new Point(pp1.X + horizontal.Advance, 0);
            var pp3 = new Point(0, glyph.MaxY + vertical.FrontSideBearing);
            var pp4 = new Point(0, pp3.Y - vertical.Advance);

            points.Add(pp1 * scale);
            points.Add(pp2 * scale);
            points.Add(pp3 * scale);
            points.Add(pp4 * scale);

            // hint the glyph's points
            var pointArray   = points.ToArray();
            var contourArray = contours.ToArray();

            return(new Glyph(pointArray, contourArray, horizontal.Advance * scale, vertical.Advance * scale));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets kerning information for a pair of characters.
        /// </summary>
        /// <param name="left">The left character.</param>
        /// <param name="right">The right character.</param>
        /// <param name="pixelSize">The size of the font, in pixels.</param>
        /// <returns>The amount of kerning to apply, if any.</returns>
        public float GetKerning(CodePoint left, CodePoint right, float pixelSize)
        {
            if (kernTable == null)
            {
                return(0.0f);
            }

            var leftIndex  = charMap.Lookup(left);
            var rightIndex = charMap.Lookup(right);

            if (leftIndex < 0 || rightIndex < 0)
            {
                return(0.0f);
            }

            var kern = kernTable.Lookup(leftIndex, rightIndex);

            return(kern * ComputeScale(pixelSize));
        }