Пример #1
0
        public float[] DrawTextLine(
            Page page, float x_text, float y_text, TextLine textLine, bool draw)
        {
            Font font = textLine.GetFont();
            Font fallbackFont = textLine.GetFallbackFont();
            int color = textLine.GetColor();

            StringBuilder buf = new StringBuilder();
            String[] tokens = Regex.Split(textLine.GetText(), "\\s+");
            bool firstTextSegment = true;
            for (int i = 0; i < tokens.Length; i++) {
            String token = (i == 0) ? tokens[i] : (" " + tokens[i]);
            if (font.StringWidth(fallbackFont, token) < (this.w - (x_text - x))) {
                buf.Append(token);
                x_text += font.StringWidth(fallbackFont, token);
            }
            else {
                if (draw) {
                    new TextLine(font, buf.ToString())
                            .SetFallbackFont(textLine.GetFallbackFont())
                            .SetLocation(x_text - font.StringWidth(fallbackFont, buf.ToString()), y_text)
                            .SetColor(color)
                            .SetUnderline(textLine.GetUnderline())
                            .SetStrikeout(textLine.GetStrikeout())
                            .SetLanguage(textLine.GetLanguage())
                            .SetAltDescription(firstTextSegment ? textLine.GetAltDescription() : Single.space)
                            .SetActualText(firstTextSegment ? textLine.GetActualText() : Single.space)
                            .DrawOn(page);
                    firstTextSegment = false;
                }
                x_text = x + font.StringWidth(fallbackFont, tokens[i]);
                y_text += leading;
                buf.Length = 0;
                buf.Append(tokens[i]);
            }
            }
            if (draw) {
            new TextLine(font, buf.ToString())
                    .SetFallbackFont(textLine.GetFallbackFont())
                    .SetLocation(x_text - font.StringWidth(fallbackFont, buf.ToString()), y_text)
                    .SetColor(color)
                    .SetUnderline(textLine.GetUnderline())
                    .SetStrikeout(textLine.GetStrikeout())
                    .SetLanguage(textLine.GetLanguage())
                    .SetAltDescription(firstTextSegment ? textLine.GetAltDescription() : Single.space)
                    .SetActualText(firstTextSegment ? textLine.GetActualText() : Single.space)
                    .DrawOn(page);
            firstTextSegment = false;
            }

            return new float[] { x_text, y_text };
        }
Пример #2
0
 /**
  *  Add a new text line.
  *
  *  Find the current font, current size and effects (normal, super or subscript)
  *  Set the position of the component to the starting stored as current position
  *  Set the size and offset based on effects
  *  Set the new current position
  *
  *  @param component the component.
  */
 public void AddComponent(TextLine component)
 {
     if (component.GetTextEffect() == Effect.SUPERSCRIPT) {
     component.GetFont().SetSize(fontSize * superscript_size_factor);
     component.SetPosition(
             current[X],
             current[Y] - fontSize * superscript_position);
     }
     else if (component.GetTextEffect() == Effect.SUBSCRIPT) {
     component.GetFont().SetSize(fontSize * subscript_size_factor);
     component.SetPosition(
             current[X],
             current[Y] + fontSize * subscript_position);
     }
     else {
     component.GetFont().SetSize(fontSize);
     component.SetPosition(current[X], current[Y]);
     }
     current[X] += component.GetWidth();
     textLines.Add(component);
 }