Package java.awt.font

Examples of java.awt.font.TextLayout


        AttributedString string = new AttributedString(" ");
        // user can pass an object to convert fonts via a rendering hint
        string.addAttribute(TextAttribute.FAMILY, getFontFamily());

        string.addAttribute(TextAttribute.SIZE, (float)getFontSize());
        TextLayout l = new TextLayout(string.getIterator(), new FontRenderContext(null, true, true));
        double wspace = l.getAdvance();

        double tabSz = _p.getDefaultTabSize();

        int numSpaces = (int)Math.ceil(tabSz / wspace);
        StringBuffer buf = new StringBuffer();
View Full Code Here


            }
        }

        // We Just want it to do BIDI for us...
        // In 1.4 we might be able to use the BIDI class...
        TextLayout tl = new TextLayout(as.getIterator(), frc);

        int[] charIndices = new int[numChars];
        int[] charLevels  = new int[numChars];

        int runStart   = 0;
        int currBiDi   = tl.getCharacterLevel(0);
        charIndices[0] = 0;
        charLevels [0] = currBiDi;
        int maxBiDi    = currBiDi;

        for (int i = 1; i < numChars; i++) {
            int newBiDi = tl.getCharacterLevel(i);
            charIndices[i] = i;
            charLevels [i] = newBiDi;

            if (newBiDi != currBiDi) {
                as.addAttribute
                    (GVTAttributedCharacterIterator.TextAttribute.BIDI_LEVEL,
                     new Integer(currBiDi), runStart, i);
                runStart = i;
                currBiDi  = newBiDi;
                if (newBiDi > maxBiDi) maxBiDi = newBiDi;
            }
        }
        as.addAttribute
            (GVTAttributedCharacterIterator.TextAttribute.BIDI_LEVEL,
             new Integer(currBiDi), runStart, numChars);

        aci = as.getIterator();

        if ((runStart == 0) && (currBiDi==0)) {
            // This avoids all the mucking about we need to do when
            // bidi is actually performed for cases where it
            // is not actually needed.
            this.reorderedACI = aci;
            newCharOrder = new int[numChars];
            for (int i=0; i<numChars; i++)
                newCharOrder[i] = chunkStart+i;
            return;
        }

        //  work out the new character order
        newCharOrder = doBidiReorder(charIndices, charLevels,
                                           numChars, maxBiDi);

        // construct the string in the new order
        StringBuffer reorderedString = new StringBuffer();
        char c;
        for (int i = 0; i < numChars; i++) {
            c = aci.setIndex(newCharOrder[i]);

            // check for mirrored char
            int bidiLevel = tl.getCharacterLevel(newCharOrder[i]);
            if ((bidiLevel & 0x01) != 0) {
                // bidi level is odd so writing dir is right to left
                // So get the mirror version of the char if there
                // is one.
                c = (char)mirrorChar(c);
View Full Code Here

     * @param g2d the Graphics2D to use
     */
    public void paint(AttributedCharacterIterator aci, Point2D location,
                      TextNode.Anchor anchor, Graphics2D g2d) {
        // Compute aci size to be able to draw it
        TextLayout layout = new TextLayout(aci, fontRenderContext);
        float advance = layout.getAdvance();
        float tx = 0;

        switch(anchor.getType()){
        case TextNode.Anchor.ANCHOR_MIDDLE:
            tx = -advance/2;
            break;
        case TextNode.Anchor.ANCHOR_END:
            tx = -advance;
        }
        layout.draw(g2d, (float)(location.getX() + tx), (float)(location.getY()));
    }
View Full Code Here

                            FontRenderContext frc = g2.getFontRenderContext();

                            Point2D.Double pen = new Point2D.Double( 0, 0 );
                            GeneralPath gp = new GeneralPath( GeneralPath.WIND_NON_ZERO );
                            TextLayout layout = new TextLayout( sr.text, font, frc );
                            pen.y += layout.getAscent();

                            if (( fontAngle != 0 ) || sr.text.startsWith("Sono una scala verticale di prevalenza") ) {
                                AffineTransform at = new AffineTransform();
                                float height = (float)layout.getBounds().getHeight();

                                AffineTransform textAt = new AffineTransform();
                                textAt.translate( x, y);
                                textAt.rotate(Math.toRadians(270));
                                textAt.translate(0, height);
                                Shape shape = layout.getOutline(textAt);
                                gp.append( at.createTransformedShape( shape )/*layout.getOutline( null ))*/, false );
                                g2.draw( shape );
                            }
                            else
                                g.drawString( sr.text, x, y );
View Full Code Here

     * @see #setComposite
     * @see #setClip
     */
    public void drawString(AttributedCharacterIterator iterator,
                           float x, float y) {
        TextLayout layout = new TextLayout(iterator, getFontRenderContext());
        layout.draw(this, x, y);
    }
View Full Code Here

      this.getGraphics2D().setPaint( this.getChartProperties().getTitleFont().getPaint() );

      //---draw each title line.  Subtract padding from each side for printable width.
      float wrappingWidth= this.getImageWidth() - ( this.getChartProperties().getEdgePadding() * 2 );

      TextLayout titleTextLayout= null;
      while( ( titleTextLayout = measurer.nextLayout( wrappingWidth ) ) != null )
      {
        //---set the current line to where the title will be written
        currentLine += titleTextLayout.getAscent();

        titleTextLayout.draw( this.getGraphics2D(),
                       ( ( this.getImageWidth() - titleTextLayout.getAdvance() ) / 2 ),
                       currentLine );

        //---keep track of total height of all the title lines
        height +=  titleTextLayout.getAscent() + titleTextLayout.getDescent();
      }

      //---add in the padding between the title and the top of the chart.
      height += this.getChartProperties().getTitlePadding();
    }
View Full Code Here

   * @param title
   * @param axisTitleFont
   **********************************************************************************************/
  public final void computeAxisTitleDimensions( String title, ChartFont axisTitleFont )
  {
    TextLayout textLayout = new TextLayout( title,
                               axisTitleFont.getFont(),
                               this.getAxisChart().getGraphics2D().getFontRenderContext() );

    this.titleWidth = textLayout.getAdvance();
    this.titleHeight = textLayout.getAscent() + textLayout.getDescent();
  }
View Full Code Here

   * @param derivedFont is the transformed font
   * @param fontRenderContext
   **********************************************************************************************/
  public TextTag( String text, Font baseFont, Font derivedFont, FontRenderContext fontRenderContext )
  {
    this.textLayout = new TextLayout( text, baseFont, fontRenderContext );

    this.isDerived = (derivedFont != null);
    this.derivedFont = derivedFont;

    //---Dimensions
View Full Code Here

        int iw = img.getWidth(this);
        int ih = img.getHeight(this);
        FontRenderContext frc = g2.getFontRenderContext();
        Font font = g2.getFont();
        g2.setColor(black);
        TextLayout tl = new TextLayout("ColorConvertOp RGB->GRAY", font, frc);
        tl.draw(g2, (float) (w/2-tl.getBounds().getWidth()/2),
                            tl.getAscent()+tl.getLeading());

        BufferedImage srcImg =
            new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
        Graphics2D srcG = srcImg.createGraphics();
        RenderingHints rhs = g2.getRenderingHints();
        srcG.setRenderingHints(rhs);
        srcG.drawImage(img, 0, 0, null);

        String s = "JavaColor";
        Font f = new Font("serif", Font.BOLD, iw/6);
        tl = new TextLayout(s, f, frc);
        Rectangle2D tlb = tl.getBounds();
        char[] chars = s.toCharArray();
        float charWidth = 0.0f;
        int rw = iw/chars.length;
        int rh = ih/chars.length;
        for (int i = 0; i < chars.length; i++) {
            tl = new TextLayout(String.valueOf(chars[i]), f, frc);
            Shape shape = tl.getOutline(null);
            srcG.setColor(colors[i%colors.length]);
            tl.draw(srcG, (float) (iw/2-tlb.getWidth()/2+charWidth),
                          (float) (ih/2+tlb.getHeight()/2));
            charWidth += (float) shape.getBounds().getWidth();
            srcG.fillRect(i*rw, ih-rh, rw, rh);
            srcG.setColor(colors[colors.length-1-i%colors.length]);
            srcG.fillRect(i*rw, 0, rw, rh);
View Full Code Here

    public void render(int w, int h, Graphics2D g2) {

        FontRenderContext frc = g2.getFontRenderContext();
        Font f = new Font("sansserif",Font.BOLD,32);
        String s = new String("JAVA");
        TextLayout tl = new TextLayout(s, f, frc);
        double sw = tl.getBounds().getWidth();
        double sh = tl.getBounds().getHeight();
        double sx = (w-40)/sw;
        double sy = (h-40)/sh;
        AffineTransform Tx = AffineTransform.getScaleInstance(sx, sy);
        Shape shape = tl.getOutline(Tx);
        sw = shape.getBounds().getWidth();
        sh = shape.getBounds().getHeight();
        Tx = AffineTransform.getTranslateInstance(w/2-sw/2, h/2+sh/2);
        shape = Tx.createTransformedShape(shape);
        Rectangle r = shape.getBounds();

        if (doClip) {
            g2.clip(shape);
        }

        if (clipType.equals("Lines")) {
            g2.setColor(BLACK);
            g2.fill(r);
            g2.setColor(YELLOW);
            g2.setStroke(new BasicStroke(1.5f));
            for (int j = r.y; j < r.y + r.height; j=j+3) {
                Line2D line = new Line2D.Float( (float) r.x, (float) j,
                                            (float) (r.x+r.width), (float) j);
                g2.draw(line);
            }
        } else if (clipType.equals("Image")) {
            g2.drawImage(img, r.x, r.y, r.width, r.height, null);
        } else if (clipType.equals("TP")) {
            g2.setPaint(texture);
            g2.fill(r);
        } else if (clipType.equals("GP")) {
            g2.setPaint(new GradientPaint(0,0,BLUE,w,h,YELLOW));
            g2.fill(r);
        } else if (clipType.equals("Text")) {
            g2.setColor(BLACK);
            g2.fill(shape.getBounds());
            g2.setColor(CYAN);
            f = new Font("serif",Font.BOLD,10);
            tl = new TextLayout("java", f, frc);
            sw = tl.getBounds().getWidth();
   
            int x = r.x;
            int y = (int) (r.y + tl.getAscent());
            sh = r.y + r.height;
            while ( y < sh ) {
                tl.draw(g2, x, y);
                if ((x += (int) sw) > (r.x+r.width)) {
                    x = r.x;
                    y += (int) tl.getAscent();
                }
            }
        }
        g2.setClip(new Rectangle(0, 0, w, h));
View Full Code Here

TOP

Related Classes of java.awt.font.TextLayout

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.