/// <summary> /// finds FontGlyph in map and returns it, or null if none. /// </summary> /// <param name="codepoint"></param> /// <returns></returns> protected virtual FontGlyph FindFontGlyph(char codepoint) { FontGlyph fontGlyph = null; d_cp_map.TryGetValue(codepoint, out fontGlyph); return(fontGlyph); }
//! Destructor. // TODO: ~PixmapFont(); public void DefineMapping(char codepoint, string image_name, float horz_advance) { var image = ImageManager.GetSingleton().Get(d_imageNamePrefix + '/' + image_name); var adv = (horz_advance == -1.0f) ? (float)(int)(image.GetRenderedSize().Width + image.GetRenderedOffset().X) : horz_advance; if (d_autoScaled != AutoScaledMode.Disabled) { adv *= d_origHorzScaling; } if (codepoint > d_maxCodepoint) { d_maxCodepoint = codepoint; } // create a new FontGlyph with given character code var glyph = new FontGlyph(adv, image, true); if (image.GetRenderedOffset().Y < -d_ascender) { d_ascender = -image.GetRenderedOffset().Y; } if (image.GetRenderedSize().Height + image.GetRenderedOffset().Y > -d_descender) { d_descender = -(image.GetRenderedSize().Height + image.GetRenderedOffset().Y); } d_height = d_ascender - d_descender; // add glyph to the map d_cp_map[codepoint] = glyph; }
/// <summary> /// initialise FontGlyph for given codepoint. /// </summary> /// <param name="cp"></param> /// <param name="fontGlyph"></param> private void InitialiseFontGlyph(char cp, FontGlyph fontGlyph) { // load-up required glyph metrics (don't render) try { var glyphIdx = d_fontFace.GetCharIndex(cp); d_fontFace.LoadGlyph(glyphIdx, LoadFlags.Default | LoadFlags.ForceAutohint, LoadTarget.Normal); var adv = (float)d_fontFace.Glyph.Metrics.HorizontalAdvance * FT_POS_COEF; fontGlyph.SetAdvance(adv); fontGlyph.SetValid(true); } catch { } }
private void InitialiseGlyphMap() { uint gindex; uint codepoint = d_fontFace.GetFirstChar(out gindex); uint maxCodepoint = codepoint; while (gindex != 0) { if (maxCodepoint < codepoint) { maxCodepoint = codepoint; } d_cp_map[(char)codepoint] = new FontGlyph(); codepoint = d_fontFace.GetNextChar(codepoint, out gindex); } SetMaxCodepoint((char)maxCodepoint); }
/// <summary> /// Calculates and returns the size this glyph takes up if it is the last character, or /// the size the glyph takes until the next character begins (considering kerning). /// </summary> /// <param name="currentCodePoint"></param> /// <param name="nextCodePoint"></param> /// <param name="isFollowedByAnotherCharacter"></param> /// <param name="?"></param> /// <param name="curExtent"></param> /// <param name="advExtent"></param> public void GetGlyphExtents(char currentCodePoint, char nextCodePoint, bool isFollowedByAnotherCharacter, ref float curExtent, ref float advExtent, float x_scale) { var currentGlyph = GetGlyphData(currentCodePoint); if (currentGlyph != null) { FontGlyph nextGlyph = null; if (isFollowedByAnotherCharacter) { nextGlyph = GetGlyphData(nextCodePoint); } var width = currentGlyph.GetRenderedAdvance(nextGlyph, x_scale); if (advExtent + width > curExtent) { curExtent = advExtent + width; } advExtent += currentGlyph.GetAdvance(x_scale); } }