public void draw( UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { final UClip clip = clipContainer.getClip(); if (clip != null && clip.isInside(x, y) == false) { return; } final UText shape = (UText) ushape; final FontConfiguration fontConfiguration = shape.getFontConfiguration(); final UFont font = fontConfiguration.getFont(); String fontWeight = null; if (fontConfiguration.containsStyle(FontStyle.BOLD) || font.isBold()) { fontWeight = "bold"; } String fontStyle = null; if (fontConfiguration.containsStyle(FontStyle.ITALIC) || font.isItalic()) { fontStyle = "italic"; } String textDecoration = null; if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) { textDecoration = "underline"; } else if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { textDecoration = "line-through"; } String backColor = null; if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) { backColor = StringUtils.getAsHtml(mapper.getMappedColor(fontConfiguration.getExtendedColor())); } svg.setFillColor(StringUtils.getAsHtml(mapper.getMappedColor(fontConfiguration.getColor()))); String text = shape.getText(); if (text.startsWith(" ")) { final double space = stringBounder.calculateDimension(font, " ").getWidth(); while (text.startsWith(" ")) { x += space; text = text.substring(1); } } text = StringUtils.trin(text); final Dimension2D dim = stringBounder.calculateDimension(font, text); svg.text( text, x, y, font.getFamily(UFontContext.SVG), font.getSize(), fontWeight, fontStyle, textDecoration, dim.getWidth(), fontConfiguration.getAttributes(), backColor); }
private void drawAsText( UText shape, double x, double y, UParam param, EpsGraphics eps, ColorMapper mapper) { final FontConfiguration fontConfiguration = shape.getFontConfiguration(); // final FontMetrics fm = g2dummy.getFontMetrics(fontConfiguration.getFont().getFont()); // final double ypos = y - fm.getDescent() + 0.5; final double ypos = y - 1; eps.setStrokeColor(mapper.getMappedColor(fontConfiguration.getColor())); ((EpsGraphicsMacroAndText) eps).drawText(shape.getText(), fontConfiguration, x, ypos); }
public void addSprite(String src) { final Sprite sprite = skinParam.getSprite(src); if (sprite != null) { atoms.add( new AtomSprite(sprite.asTextBlock(fontConfiguration.getColor()), fontConfiguration)); } }
public class GanttDiagram2 { private final Project2 project; private final double dayWith = 20; public GanttDiagram2(Project2 project) { this.project = project; } private final UFont font = new UFont("Serif", Font.PLAIN, 9); private final FontConfiguration fontConfig = FontConfiguration.blackBlueTrue(font); public void draw(UGraphic ug, double x, double y) { final TextBlock timeHeader = project.getTimeHeader(dayWith); final Row row = getMainRow(); final TextBlock headers = row.header(); final double deltaX = headers.calculateDimension(ug.getStringBounder()).getWidth(); final double deltaY = timeHeader.calculateDimension(ug.getStringBounder()).getHeight(); headers.drawU(ug.apply(new UTranslate(x, (y + deltaY)))); final TextBlock tbRow = row.asTextBloc(project.getTimeConverter(dayWith)); tbRow.drawU(ug.apply(new UTranslate((x + deltaX), (y + deltaY)))); timeHeader.drawU(ug.apply(new UTranslate((x + deltaX), y))); } private Row getMainRow() { final List<Task> tasks = project.getTasks(); final List<Row> rows = new ArrayList<Row>(); for (Task t : tasks) { final String text = t.getCode(); final TextBlock label = Display.create(text).create(fontConfig, HorizontalAlignment.LEFT, new SpriteContainerEmpty()); rows.add(new RowSimple((Day) t.getStart(), (Day) t.getEnd(), HtmlColorUtils.BLACK, TextBlockUtils .withMargin(label, 3, 3))); } final Row row = RowUtils.merge(rows); return row; } public double getWidth(StringBounder stringBounder) { final TextBlock timeHeader = project.getTimeHeader(dayWith); final Row row = getMainRow(); final TextBlock headers = row.header(); return headers.calculateDimension(stringBounder).getWidth() + timeHeader.calculateDimension(stringBounder).getWidth() + 1; } public double getHeight(StringBounder stringBounder) { final TextBlock timeHeader = project.getTimeHeader(dayWith); final Row row = getMainRow(); final TextBlock headers = row.header(); return headers.calculateDimension(stringBounder).getHeight() + timeHeader.calculateDimension(stringBounder).getHeight(); } }
class ItemHeader { private final UFont font = new UFont("Serif", Font.PLAIN, 9); private final Project project; private final FontConfiguration fontConfig = FontConfiguration.blackBlueTrue(font); public ItemHeader(Project project) { this.project = project; } public void draw(UGraphic ug, double x, double y) { final StringBounder stringBounder = ug.getStringBounder(); ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK)); ug.apply(new UTranslate(x, y)) .draw(new URectangle(getWidth(stringBounder), getHeight(stringBounder))); for (Item it : project.getValidItems()) { final TextBlock b = Display.create("" + it.getCode()) .create(fontConfig, HorizontalAlignment.LEFT, new SpriteContainerEmpty()); final Dimension2D dim = b.calculateDimension(stringBounder); b.drawU(ug.apply(new UTranslate(x, y))); y += dim.getHeight(); ug.apply(new UTranslate(x, y)).draw(new ULine(getWidth(stringBounder), 0)); } } public double getWidth(StringBounder stringBounder) { double width = 0; for (Item it : project.getValidItems()) { final Dimension2D dim = stringBounder.calculateDimension(font, it.getCode()); width = Math.max(width, dim.getWidth()); } return width; } public double getHeight(StringBounder stringBounder) { double height = 0; for (Item it : project.getValidItems()) { final Dimension2D dim = stringBounder.calculateDimension(font, it.getCode()); height += dim.getHeight(); } return height; } public double getPosition(StringBounder stringBounder, Item item) { double pos = 0; for (Item it : project.getValidItems()) { if (it == item) { return pos; } final Dimension2D dim = stringBounder.calculateDimension(font, it.getCode()); pos += dim.getHeight(); } throw new IllegalArgumentException(); } }
public EntityImageDefault(IEntity entity) { super(entity); this.textBlock = entity .getDisplay() .create( FontConfiguration.blackBlueTrue(getFont14()), HorizontalAlignment.CENTER, new SpriteContainerEmpty()); }
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { final Display display = Display.create(lines); final UFont font = new UFont("Serif", Font.PLAIN, 14); final FontConfiguration fontConfiguration = FontConfiguration.blackBlueTrue(font); final Sheet sheet = new CreoleParser(fontConfiguration, HorizontalAlignment.LEFT, null, CreoleMode.FULL) .createSheet(display); final SheetBlock1 sheetBlock = new SheetBlock1(sheet, 0, 0); final ImageBuilder builder = new ImageBuilder(new ColorMapperIdentity(), 1.0, null, null, null, 0, 0, null, false); builder.setUDrawable(sheetBlock); return builder.writeImageTOBEMOVED(fileFormat, os); // final Dimension2D dim = TextBlockUtils.getDimension(sheetBlock); // final UGraphic2 ug = fileFormat.createUGraphic(new ColorMapperIdentity(), 1, dim, null, // false); // // sheetBlock.drawU(ug.apply(new UTranslate(0, 10))); // sheetBlock.drawU(ug); // ug.writeImageTOBEMOVED(os, null, 96); // return new ImageDataSimple(dim); }
private TextBlock createStereotype( FontConfiguration fontConfiguration, HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer, int position, UFont fontForStereotype, HtmlColor htmlColorForStereotype) { final Stereotype stereotype = (Stereotype) get(position); if (stereotype.isSpotted()) { final CircledCharacter circledCharacter = new CircledCharacter( stereotype.getCharacter(), stereotype.getRadius(), stereotype.getCircledFont(), stereotype.getHtmlColor(), null, fontConfiguration.getColor()); if (stereotype.getLabel(false) == null) { return new TextBlockSpotted( circledCharacter, this.subList(1, this.size()), fontConfiguration, horizontalAlignment, spriteContainer); } return new TextBlockSpotted( circledCharacter, this, fontConfiguration, horizontalAlignment, spriteContainer); } return new TextBlockSimple( this, fontConfiguration, horizontalAlignment, spriteContainer, 0, fontForStereotype, htmlColorForStereotype); }
public class TimeHeaderMonth extends AbstractTextBlock implements TextBlock { private final Day start; private final Day end; private final TimeLine timeline; private final double dayWidth; private final UFont font = new UFont("Serif", Font.PLAIN, 9); private final FontConfiguration fontConfig = FontConfiguration.blackBlueTrue(font); public TimeHeaderMonth(Day start, Day end, TimeLine timeline, double dayWidth) { this.start = start; this.end = end; this.timeline = timeline; this.dayWidth = dayWidth; } public void drawU(UGraphic ug) { int n = 0; String last = null; double pendingX = -1; for (Day d = start; d.compareTo(end) <= 0; d = (Day) timeline.next(d)) { final String text = "" + d.getMonth().name(); if (pendingX == -1) { pendingX = n * dayWidth; last = text; } ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK)); ug = ug.apply(new UChangeBackColor(HtmlColorUtils.WHITE)); if (text.equals(last) == false) { manage(ug, 0, 0, n, last, pendingX); pendingX = n * dayWidth; } last = text; n++; } manage(ug, 0, 0, n, last, pendingX); } private void manage(UGraphic ug, double x, double y, int n, String last, double pendingX) { final double width = n * dayWidth - pendingX; ug.apply(new UTranslate(x + pendingX, y)).draw(new URectangle(width, getHeight())); final TextBlock b = Display.create(last) .create(fontConfig, HorizontalAlignment.LEFT, new SpriteContainerEmpty()); final Dimension2D dimText = b.calculateDimension(ug.getStringBounder()); final double diffX = width - dimText.getWidth(); final double diffY = getHeight() - dimText.getHeight(); b.drawU(ug.apply(new UTranslate((x + pendingX + diffX / 2), (y + diffY / 2)))); } private double getHeight() { return 20; } public Dimension2D calculateDimension(StringBounder stringBounder) { int n = 0; for (Day d = start; d.compareTo(end) <= 0; d = (Day) timeline.next(d)) { n++; } return new Dimension2DDouble(n * dayWidth, getHeight()); } }
public void draw( UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) { final UClip clip = clipContainer.getClip(); if (clip != null && clip.isInside(x, y) == false) { return; } final UText shape = (UText) ushape; if (strategy == EpsStrategy.WITH_MACRO_AND_TEXT) { drawAsText(shape, x, y, param, eps, mapper); return; } final FontConfiguration fontConfiguration = shape.getFontConfiguration(); final UFont font = fontConfiguration.getFont(); final TextLayout t = new TextLayout(shape.getText(), font.getFont(), fontRenderContext); eps.setStrokeColor(mapper.getMappedColor(fontConfiguration.getColor())); drawPathIterator(eps, x, y, t.getOutline(null).getPathIterator(null)); if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) { final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { eps.setStrokeColor(mapper.getMappedColor(extended)); } final Dimension2D dim = DriverTextG2d.calculateDimension(stringBounder, font, shape.getText()); eps.setStrokeWidth("1.1", 0, 0); eps.epsLine(x, y + 1.5, x + dim.getWidth(), y + 1.5); eps.setStrokeWidth("1", 0, 0); } if (fontConfiguration.containsStyle(FontStyle.WAVE)) { final Dimension2D dim = DriverTextG2d.calculateDimension(stringBounder, font, shape.getText()); final int ypos = (int) (y + 2.5) - 1; final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { eps.setStrokeColor(mapper.getMappedColor(extended)); } eps.setStrokeWidth("1.1", 0, 0); for (int i = (int) x; i < x + dim.getWidth() - 5; i += 6) { eps.epsLine(i, ypos - 0, i + 3, ypos + 1); eps.epsLine(i + 3, ypos + 1, i + 6, ypos - 0); } eps.setStrokeWidth("1", 0, 0); } if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { eps.setStrokeColor(mapper.getMappedColor(extended)); } final Dimension2D dim = DriverTextG2d.calculateDimension(stringBounder, font, shape.getText()); final FontMetrics fm = g2dummy.getFontMetrics(font.getFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); eps.setStrokeWidth("1.3", 0, 0); eps.epsLine(x, ypos, x + dim.getWidth(), ypos); eps.setStrokeWidth("1", 0, 0); } }
public double getDescent() { final LineMetrics fm = TextBlockUtils.getLineMetrics(font.getFont(), text); final double descent = fm.getDescent(); return descent; }