Package org.pdfclown.documents.contents.fonts

Examples of org.pdfclown.documents.contents.fonts.Font


    if(currentRow == null
      || text == null)
      return 0;

    ContentScanner.GraphicsState state = baseComposer.getState();
    Font font = state.getFont();
    float fontSize = state.getFontSize();
    float lineHeight = font.getLineHeight(fontSize);

    TextFitter textFitter = new TextFitter(
      text,
      0,
      font,
View Full Code Here


    AlignmentYEnum alignmentY,
    float rotation
    )
  {
    ContentScanner.GraphicsState state = scanner.getState();
    Font font = state.getFont();
    float fontSize = state.getFontSize();
    float x = (float)location.getX();
    float y = (float)location.getY();
    float width = font.getKernedWidth(value,fontSize);
    float height = font.getLineHeight(fontSize);
    float descent = font.getDescent(fontSize);

    Point2D[] frame = new Point2D[4];

    if(alignmentX == AlignmentXEnum.Left
      && alignmentY == AlignmentYEnum.Top)
    {
      beginText();
      try
      {
        if(rotation == 0)
        {
          translateText(
            x,
            (float)(scanner.getContentContext().getBox().getHeight() - y - font.getAscent(fontSize))
            );
        }
        else
        {
          double rad = rotation * Math.PI / 180.0;
          double cos = Math.cos(rad);
          double sin = Math.sin(rad);

          setTextMatrix(
            cos,
            sin,
            -sin,
            cos,
            x,
            scanner.getContentContext().getBox().getHeight() - y - font.getAscent(fontSize)
            );
        }

        state = scanner.getState();
        frame[0] = state.textToDeviceSpace(new Point2D.Double(0,descent),true);
        frame[1] = state.textToDeviceSpace(new Point2D.Double(width,descent),true);
        frame[2] = state.textToDeviceSpace(new Point2D.Double(width,height+descent),true);
        frame[3] = state.textToDeviceSpace(new Point2D.Double(0,height+descent),true);

        // Add the text!
        add(new ShowSimpleText(font.encode(value)));
      }
      catch(Exception e)
      {throw new RuntimeException("Failed to show text.", e);}
      finally
      {end(); /* Ends the text object. */}
    }
    else
    {
      beginLocalState();
      try
      {
        // Coordinates transformation.
        double cos, sin;
        if(rotation == 0)
        {
          cos = 1;
          sin = 0;
        }
        else
        {
          double rad = rotation * Math.PI / 180.0;
          cos = Math.cos(rad);
          sin = Math.sin(rad);
        }
        // Apply the transformation!
        applyMatrix(
          cos,
          sin,
          -sin,
          cos,
          x,
          scanner.getContentContext().getBox().getHeight() - y
          );

        beginText();
        try
        {
          // Text coordinates adjustment.
          switch(alignmentX)
          {
            case Left:
              x = 0;
              break;
            case Right:
              x = -width;
              break;
            case Center:
            case Justify:
              x = -width / 2;
              break;
          }
          switch(alignmentY)
          {
            case Top:
              y = -font.getAscent(fontSize);
              break;
            case Bottom:
              y = height - font.getAscent(fontSize);
              break;
            case Middle:
              y = height / 2 - font.getAscent(fontSize);
              break;
          }
          // Apply the text coordinates adjustment!
          translateText(x,y);

          state = scanner.getState();
          frame[0] = state.textToDeviceSpace(new Point2D.Double(0,descent),true);
          frame[1] = state.textToDeviceSpace(new Point2D.Double(width,descent),true);
          frame[2] = state.textToDeviceSpace(new Point2D.Double(width,height+descent),true);
          frame[3] = state.textToDeviceSpace(new Point2D.Double(0,height+descent),true);

          // Add the text!
          add(new ShowSimpleText(font.encode(value)));
        }
        catch(Exception e)
        {throw new RuntimeException("Failed to show text.", e);}
        finally
        {end(); /* Ends the text object. */}
 
View Full Code Here

    PrimitiveComposer composer
    )
  {
    ContentObject barcodeObject = composer.beginLocalState();
    {
      Font font = new StandardType1Font(
        composer.getScanner().getContents().getDocument(),
        StandardType1Font.FamilyEnum.Helvetica,
        false,
        false
        );
      float fontSize = (DigitGlyphWidth / font.getWidth(code.substring(0,1), 1));

      // 1. Bars.
      {
        float elementX = DigitWidth;
        int[] elementWidths = getElementWidths();

        float guardBarIndentY = DigitHeight / 2;
        boolean isBar = true;
        for(
          int elementIndex = 0;
          elementIndex < elementWidths.length;
          elementIndex++
          )
        {
          float elementWidth = elementWidths[elementIndex];
          // Dark element?
          /*
            NOTE: EAN symbol elements alternate bars to spaces.
          */
          if(isBar)
          {
            composer.drawRectangle(
              new Rectangle2D.Double(
                elementX,
                0,
                elementWidth,
                BarHeight + (
                  // Guard bar?
                  Arrays.binarySearch(GuardBarIndexes, elementIndex) >= 0
                    ? guardBarIndentY // Guard bar.
                    : 0 // Symbol character.
                  )
                )
              );
          }

          elementX += elementWidth;
          isBar = !isBar;
        }
        composer.fill();
      }

      // 2. Digits.
      {
        composer.setFont(font,fontSize);
        float digitY = BarHeight + (DigitHeight - (font.getAscent(fontSize))) / 2;
        // Showing the digits...
        for(
          int digitIndex = 0;
          digitIndex < 13;
          digitIndex++
          )
        {
          String digit = code.substring(digitIndex, digitIndex+1);
          float pX = DigitGlyphXs[digitIndex] // Digit position.
            - font.getWidth(digit,fontSize) / 2; // Centering.
          // Show the current digit!
          composer.showText(
            digit,
            new Point2D.Double(pX,digitY)
            );
View Full Code Here

      pageSize.getWidth() - Margin_X * 2,
      pageSize.getHeight() - Margin_Y * 2
      );
    // Begin the title block!
    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
    Font decorativeFont = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "Ruritania-Outline.ttf"
      );
    composer.setFont(decorativeFont,56);
    blockComposer.showText("Chapter 1");
    blockComposer.showBreak();
    composer.setFont(decorativeFont,32);
    blockComposer.showText("Down the Rabbit-Hole");
    // End the title block!
    blockComposer.end();

    // Update the block frame to begin after the title!
    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight(),
      blockComposer.getBoundBox().getWidth(),
      pageSize.getHeight() - Margin_Y - (blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight())
      );
    // Begin the body block!
    blockComposer.begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Bottom);
    Font bodyFont = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "TravelingTypewriter.otf"
      );
    composer.setFont(bodyFont,14);
    composer.beginLocalState();
View Full Code Here

    while(level.moveNext())
    {
      ContentObject content = level.getCurrent();
      if(content instanceof ShowText)
      {
        Font font = level.getState().getFont();
        // Extract the current text chunk, decoding it!
        System.out.println(font.decode(((ShowText)content).getText()));
      }
      else if(content instanceof Text
        || content instanceof ContainerObject)
      {
        // Scan the inner level!
View Full Code Here

    BlockComposer blockComposer = new BlockComposer(composer);
    blockComposer.setHyphenation(true);

    Dimension breakSize = new Dimension(0,10);
    // Add the font to the document!
    Font font = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "TravelingTypewriter.otf"
      );

    Rectangle2D frame = new Rectangle2D.Double(
View Full Code Here

    */
    BlockComposer blockComposer = new BlockComposer(composer);

    Dimension breakSize = new Dimension(0,20); // Size of a paragraph break.
    // Instantiate the page body's font!
    Font font = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "lazyDog.ttf"
      );

    // Showing the page title...
View Full Code Here

      TODO: support to vertical writing mode.
    */

    IContentContext context = state.getScanner().getContentContext();
    double contextHeight = context.getBox().getHeight();
    Font font = state.getFont();
    float fontSize = state.getFontSize();
    float scale = state.getScale() / 100;
    float scaledFactor = Font.getScalingFactor(fontSize) * scale;
    float wordSpace = state.getWordSpace() * scale;
    float charSpace = state.getCharSpace() * scale;
    AffineTransform ctm = (AffineTransform)state.getCtm().clone();
    AffineTransform tm;
    if(this instanceof ShowTextToNextLine)
    {
      ShowTextToNextLine showTextToNextLine = (ShowTextToNextLine)this;
      Float newWordSpace = showTextToNextLine.getWordSpace();
      if(newWordSpace != null)
      {
        if(textScanner == null)
        {state.setWordSpace(newWordSpace);}
        wordSpace = newWordSpace * scale;
      }
      Float newCharSpace = showTextToNextLine.getCharSpace();
      if(newCharSpace != null)
      {
        if(textScanner == null)
        {state.setCharSpace(newCharSpace);}
        charSpace = newCharSpace * scale;
      }
      tm = (AffineTransform)state.getTlm().clone();
      tm.translate(0, state.getLead());
    }
    else
    {tm = (AffineTransform)state.getTm().clone();}

    for(Object textElement : getValue())
    {
      if(textElement instanceof byte[]) // Text string.
      {
        String textString = font.decode((byte[])textElement);
        for(char textChar : textString.toCharArray())
        {
          float charWidth = font.getWidth(textChar) * scaledFactor;

          if(textScanner != null)
          {
            /*
              NOTE: The text rendering matrix is recomputed before each glyph is painted
              during a text-showing operation.
            */
            AffineTransform trm = (AffineTransform)ctm.clone(); trm.concatenate(tm);
            float charHeight = font.getHeight(textChar,fontSize);
            Rectangle2D charBox = new Rectangle2D.Double(
              trm.getTranslateX(),
              contextHeight - trm.getTranslateY() - font.getAscent(fontSize) * tm.getScaleY(),
              charWidth * tm.getScaleX(),
              charHeight * tm.getScaleY()
              );
            textScanner.scanChar(textChar,charBox);
          }
View Full Code Here

    // 2.2. Create a block composer!
    BlockComposer blockComposer = new BlockComposer(composer);

    // 3. Inserting contents...
    // Define the font to use!
    Font font = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "GenR102.TTF"
      );
    // Define the paragraph break size!
    Dimension breakSize = new Dimension(0,10);
View Full Code Here

TOP

Related Classes of org.pdfclown.documents.contents.fonts.Font

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.