/** * Compute the cumulative height occupied by the text * * @param oldGraphics the graphics context, which properties are to be copied, may be null * @return the height in points */ public double getTextHeight(Graphics2D oldGraphics) { // dry-run in a 1x1 image and return the vertical advance BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); if (oldGraphics != null) { graphics.addRenderingHints(oldGraphics.getRenderingHints()); graphics.setTransform(oldGraphics.getTransform()); } DrawFactory.getInstance(graphics).fixFonts(graphics); return drawParagraphs(graphics, 0, 0); }
protected Drawable getGroupShape(Graphics2D graphics) { if (shape instanceof GroupShape) { DrawFactory df = DrawFactory.getInstance(graphics); return df.getDrawable((GroupShape<?,?>)shape); } return null; }
/** * Returns the DrawFactory, preferably via a graphics instance. * If graphics is null, the current thread local is checked or * if it is not set, a new factory is created. * * @param graphics the current graphics context or null * @return the draw factory */ public static DrawFactory getInstance(Graphics2D graphics) { // first try to find the factory over the rendering hint DrawFactory factory = null; boolean isHint = false; if (graphics != null) { factory = (DrawFactory)graphics.getRenderingHint(Drawable.DRAW_FACTORY); isHint = (factory != null); } // secondly try the thread local default if (factory == null) { factory = defaultFactory.get(); } // and at last, use the default factory if (factory == null) { factory = new DrawFactory(); } if (graphics != null && !isHint) { graphics.setRenderingHint(Drawable.DRAW_FACTORY, factory); } return factory; }
@Override public void draw(Graphics2D graphics, Rectangle2D bounds) { DrawFactory.getInstance(graphics).drawShape(graphics, this, bounds); }
@SuppressWarnings("rawtypes") public void draw(Graphics2D graphics) { Dimension pg = shape.getSheet().getSlideShow().getPageSize(); final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight()); PlaceableShape<?,?> ps = new PlaceableShape(){ public ShapeContainer<?,?> getParent() { return null; } public Rectangle2D getAnchor() { return anchor; } public void setAnchor(Rectangle2D newAnchor) {} public double getRotation() { return 0; } public void setRotation(double theta) {} public void setFlipHorizontal(boolean flip) {} public void setFlipVertical(boolean flip) {} public boolean getFlipHorizontal() { return false; } public boolean getFlipVertical() { return false; } public Sheet<?,?> getSheet() { return shape.getSheet(); } }; DrawFactory drawFact = DrawFactory.getInstance(graphics); DrawPaint dp = drawFact.getPaint(ps); Paint fill = dp.getPaint(graphics, getShape().getFillStyle().getPaint()); Rectangle2D anchor2 = getAnchor(graphics, anchor); if(fill != null) { graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, anchor); graphics.setPaint(fill); graphics.fill(anchor2); } }
lines.clear(); DrawFactory fact = DrawFactory.getInstance(graphics); fact.fixFonts(graphics); StringBuilder text = new StringBuilder(); AttributedString at = getAttributedString(graphics, text); DrawTextFragment line = fact.getTextFragment(layout, str); lines.add(line);
DrawFontManager dfm = DrawFactory.getInstance(graphics).getFontManager(graphics); DrawFactory fact = DrawFactory.getInstance(graphics); return fact.getTextFragment(layout, str);
DrawFontManager dfm = DrawFactory.getInstance(graphics).getFontManager(graphics); assert(dfm != null);
public Drawable getDrawable(Shape<?,?> shape) { if (shape instanceof TextBox) { return getDrawable((TextBox<?,?>)shape); } else if (shape instanceof FreeformShape) { return getDrawable((FreeformShape<?,?>)shape); } else if (shape instanceof TextShape) { return getDrawable((TextShape<?,?>)shape); } else if (shape instanceof TableShape) { return getDrawable((TableShape<?,?>)shape); } else if (shape instanceof GroupShape) { return getDrawable((GroupShape<?,?>)shape); } else if (shape instanceof PictureShape) { return getDrawable((PictureShape<?,?>)shape); } else if (shape instanceof GraphicalFrame) { return getDrawable((GraphicalFrame<?,?>)shape); } else if (shape instanceof Background) { return getDrawable((Background<?,?>)shape); } else if (shape instanceof ConnectorShape) { return getDrawable((ConnectorShape<?,?>)shape); } else if (shape instanceof Slide) { return getDrawable((Slide<?,?>)shape); } else if (shape instanceof MasterSheet) { return getDrawable((MasterSheet<?,?>)shape); } else if (shape instanceof Sheet) { return getDrawable((Sheet<?,?>)shape); } else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) { return new DrawNothing(shape);
DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(ts); final int rows = ts.getNumberOfRows(); final int cols = ts.getNumberOfColumns();
lines.clear(); DrawFactory fact = DrawFactory.getInstance(graphics); fact.fixFonts(graphics); StringBuilder text = new StringBuilder(); AttributedString at = getAttributedString(graphics, text); DrawTextFragment line = fact.getTextFragment(layout, str); lines.add(line);
DrawFontManager dfm = DrawFactory.getInstance(graphics).getFontManager(graphics); DrawFactory fact = DrawFactory.getInstance(graphics); return fact.getTextFragment(layout, str);
@Override public void draw(Graphics2D graphics, Rectangle2D bounds) { DrawFactory.getInstance(graphics).drawShape(graphics, this, bounds); }
private void addAttributes(AttributedString as, HwmfFont font) { DrawFontManager fontHandler = DrawFactory.getInstance(graphicsCtx).getFontManager(graphicsCtx); FontInfo fontInfo = fontHandler.getMappedFont(graphicsCtx, font); as.addAttribute(TextAttribute.FAMILY, fontInfo.getTypeface()); as.addAttribute(TextAttribute.SIZE, getFontHeight(font)); as.addAttribute(TextAttribute.STRIKETHROUGH, font.isStrikeOut()); if (font.isUnderline()) { as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } if (font.isItalic()) { as.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); } as.addAttribute(TextAttribute.WEIGHT, font.getWeight()); }
Drawable d = getDrawable(shape); d.applyTransform(graphics); d.draw(graphics);
/** * Render this sheet into the supplied graphics object * * @param graphics the graphics context to draw to */ @Override public void draw(Graphics2D graphics){ DrawFactory drawFact = DrawFactory.getInstance(graphics); Drawable draw = drawFact.getDrawable(this); draw.draw(graphics); }
DrawFactory.getInstance(graphics).fixFonts(graphics);
@Override public void draw(Graphics2D graphics) { DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(getShape()); Paint fill = drawPaint.getPaint(graphics, getShape().getFillStyle().getPaint()); Paint line = drawPaint.getPaint(graphics, getShape().getStrokeStyle().getPaint());
@Override public void draw(Graphics2D graphics, Rectangle2D bounds){ DrawFactory.getInstance(graphics).drawShape(graphics, this, bounds); }
DrawFontManager dfm = DrawFactory.getInstance(graphics).getFontManager(graphics); assert(dfm != null);