Beispiel #1
0
        // char, largura
        private List <(char, int)> CalcCharWidths(string text_line, bool kerning)
        {
            char?last_char            = null;
            List <(char, int)> result = new List <(char, int)>(text_line.Length);

            foreach (char current_char in text_line)
            {
                if ((current_char <= char_space) && (last_char == char_space))
                {
                    // ignorar espaços duplos e caracteres de controle
                    continue;
                }
                char            this_char    = (char)Math.Max((int)current_char, (int)char_space);
                PdfGlyphMetrics char_metrics = glyphMetrics[(int)this_char];
                int             width        = char_metrics.Width;
                if (kerning && (last_char != null))
                {
                    string kerning_pair = $"{glyphMetrics[(int)last_char].GlyphName}+{char_metrics.GlyphName}";
                    if (kerningPairs.TryGetValue(kerning_pair.GetHashCode(), out int adjust))
                    {
                        width += adjust;
                    }
                }
                result.Add((this_char, width));
            }
            return(result);
        }
Beispiel #2
0
        public void AddGlyphMetrics(string glyph_name, int width, int llx, int lly, int urx, int ury)
        {
            PdfGlyphMetrics glyph_metrics = new PdfGlyphMetrics(glyph_name, width, llx, lly, urx, ury);
            int             codepoint     = PdfFontCharTable.GetCodePoint(glyph_name);

            if (!glyphMetrics.ContainsKey(codepoint))
            {
                glyphMetrics.Add(codepoint, glyph_metrics);
            }
        }