/// <summary>Gets or synthesises a glyph for the given style settings which include weight and italic. Style code 400 means regular.</summary>
        public Glyph GetGlyph(int charcode, FontFaceFlags style)
        {
            // Try getting the face:
            FontFace face = null;

            if (FontFaces.TryGetValue(style, out face))
            {
                // Great! Raster using that font face:
                return(face.GetGlyph(charcode));
            }

            // Get the code as an int:
            int styleCode = (int)style;

            // Italic?
            bool italic = ((styleCode & 1) == 1);

            // Get the font weight:
            int weight = (styleCode & ~1);

            if (weight == 0)
            {
                // Regular:
                weight = 400;
            }

            int match = 0;

            if (italic)
            {
                // Find one with the closest weight match.
                face = BestWeight(Italics, weight, out match);
            }
            else if (weight == 400)
            {
                // Regular. Note that regular must be set - the family wouldn't exist otherwise.
                return(Regular.GetGlyph(charcode));
            }
            else
            {
                // Find best weight match. Must also be not italic (this is why the bold set doesn't contain italic ones).
                face = BestWeight(Bold, weight, out match);
            }

            if (face == null || match != 0)
            {
                // We're synthesizing!

                if (face == null)
                {
                    face = Regular;
                }

                // Derive from face.
                face = face.CreateSynthetic(italic, weight);
            }

            return(face.GetGlyph(charcode));
        }
Example #2
0
        /// <summary>Gets or synthesises a glyph for the given style settings which include weight and italic. Style code 400 means regular.</summary>
        /// <param name='firstTime'>True if this glyph was seen for the first time.</param>
        public Glyph GetGlyph(int charcode, int styleCode, out bool firstTime)
        {
            // Get or synth the face:
            FontFace face = GetFace(styleCode, FontSynthesisFlags.All);

            return(face.GetGlyph(charcode, out firstTime));
        }