use of java.text.AttributedString in project adempiere by adempiere.
the class StringElement method paint.
// getDrillAcross
/**************************************************************************
* Paint/Print.
* Calculate actual Size.
* The text is printed in the topmost left position - i.e. the leading is below the line
* @param g2D Graphics
* @param pageStart top left Location of page
* @param pageNo page number for multi page support (0 = header/footer) - ignored
* @param ctx print context
* @param isView true if online view (IDs are links)
*/
public void paint(Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView) {
// log.finest( "StringElement.paint", "<" + m_originalString + "> " + p_pageLocation.x + "/" + p_pageLocation.y
// + ", Clip=" + g2D.getClip()
// + ", Translate=" + g2D.getTransform().getTranslateX() + "/" + g2D.getTransform().getTranslateY()
// + ", Scale=" + g2D.getTransform().getScaleX() + "/" + g2D.getTransform().getScaleY()
// + ", Shear=" + g2D.getTransform().getShearX() + "/" + g2D.getTransform().getShearY());
Point2D.Double location = getAbsoluteLocation(pageStart);
//
if (m_originalString != null)
translate(ctx);
AttributedString aString = null;
AttributedCharacterIterator iter = null;
AttributedCharacterIterator iter2 = null;
float xPos = (float) location.x;
float yPos = (float) location.y;
float yPen = 0f;
float height = 0f;
float width = 0f;
// for all lines
for (int i = 0; i < m_string_paper.length; i++) {
// Get Text
if (isView) {
if (m_string_view[i] == null)
continue;
aString = m_string_view[i];
} else {
if (m_string_paper[i] == null)
continue;
aString = m_string_paper[i];
}
iter = aString.getIterator();
// Zero Length
if (iter.getBeginIndex() == iter.getEndIndex())
continue;
// Check for Tab (just first) and 16 bit characters
int tabPos = -1;
boolean is8Bit = true;
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
if (c == '\t' && tabPos == -1)
tabPos = iter.getIndex();
if (c > 255)
is8Bit = false;
}
TextLayout layout = null;
float xPen = xPos;
// No Limit
if (p_maxWidth == 0f) {
if (tabPos == -1) {
layout = new TextLayout(iter, g2D.getFontRenderContext());
yPen = yPos + layout.getAscent();
// layout.draw(g2D, xPen, yPen);
g2D.setFont(m_font);
g2D.setPaint(m_paint);
g2D.drawString(iter, xPen, yPen);
//
yPos += layout.getAscent() + layout.getDescent() + layout.getLeading();
if (width < layout.getAdvance())
width = layout.getAdvance();
} else // we have a tab
{
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
layout = measurer.nextLayout(9999, tabPos, false);
float lineHeight_1 = layout.getAscent() + layout.getDescent() + layout.getLeading();
yPen = yPos + layout.getAscent();
// first part before tab
layout.draw(g2D, xPen, yPen);
xPen = getTabPos(xPos, layout.getAdvance());
float lineWidth = xPen - xPos;
//, iter.getEndIndex(), true);
layout = measurer.nextLayout(9999);
float lineHeight_2 = layout.getAscent() + layout.getDescent() + layout.getLeading();
// second part after tab
layout.draw(g2D, xPen, yPen);
//
yPos += Math.max(lineHeight_1, lineHeight_2);
lineWidth += layout.getAdvance();
if (width < lineWidth)
width = lineWidth;
}
// log.finest( "StringElement.paint - No Limit - " + location.x + "/" + yPos
// + " w=" + layout.getAdvance() + ",h=" + lineHeight + ", Bounds=" + layout.getBounds());
} else // Size Limits
{
boolean fastDraw = LayoutEngine.s_FASTDRAW;
if (fastDraw && !isView && !is8Bit)
fastDraw = false;
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
while (measurer.getPosition() < iter.getEndIndex()) {
if (tabPos == -1) {
layout = measurer.nextLayout(p_maxWidth);
if (measurer.getPosition() < iter.getEndIndex())
fastDraw = false;
} else // tab
{
fastDraw = false;
layout = measurer.nextLayout(p_maxWidth, tabPos, false);
}
// Line Height
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (// one line only
p_maxHeight == -1f && i == 0)
p_maxHeight = lineHeight;
// If we have hight left over
if (p_maxHeight == 0f || (height + lineHeight) <= p_maxHeight) {
yPen = (float) location.y + height + layout.getAscent();
// Tab in Text
if (tabPos != -1) {
// first part before tab
layout.draw(g2D, xPen, yPen);
xPen = getTabPos(xPos, layout.getAdvance());
layout = measurer.nextLayout(p_width, iter.getEndIndex(), true);
// reset (just one tab)
tabPos = -1;
} else if ((MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight.equals(p_FieldAlignmentType) && layout.isLeftToRight()) || (MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft.equals(p_FieldAlignmentType) && !layout.isLeftToRight()))
xPen += p_maxWidth - layout.getAdvance();
else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Center.equals(p_FieldAlignmentType))
xPen += (p_maxWidth - layout.getAdvance()) / 2;
else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Block.equals(p_FieldAlignmentType) && measurer.getPosition() < iter.getEndIndex()) {
layout = layout.getJustifiedLayout(p_maxWidth);
fastDraw = false;
}
if (fastDraw) {
g2D.setFont(m_font);
g2D.setPaint(m_paint);
g2D.drawString(iter, xPen, yPen);
height += lineHeight;
break;
} else {
layout.draw(g2D, xPen, yPen);
}
height += lineHeight;
// log.finest( "StringElement.paint - Limit - " + xPen + "/" + yPen
// + " w=" + layout.getAdvance() + ",h=" + lineHeight + ", Align=" + p_FieldAlignmentType + ", Max w=" + p_maxWidth + ",h=" + p_maxHeight + ", Bounds=" + layout.getBounds());
}
}
width = p_maxWidth;
}
// size limits
}
// for all strings
if (m_check != null) {
int x = (int) (location.x + width + 1);
int y = (int) (location.y);
g2D.drawImage(m_check.booleanValue() ? LayoutEngine.IMAGE_TRUE : LayoutEngine.IMAGE_FALSE, x, y, this);
}
}
use of java.text.AttributedString in project adempiere by adempiere.
the class StringElement method translate.
// getOrig
/**
* Translate Context if required
* If content is translated, the element needs to stay in the bounds
* of the originally calculated size and need to align the field.
* @param ctx context
*/
public void translate(Properties ctx) {
if (m_originalString == null)
return;
String inText = Msg.parseTranslation(ctx, m_originalString);
// log.fine( "StringElement.translate", inText);
String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(inText);
m_string_paper = new AttributedString[lines.length];
for (int i = 0; i < lines.length; i++) {
String line = Util.removeCRLF(lines[i]);
m_string_paper[i] = new AttributedString(line);
if (line.length() > 0) {
m_string_paper[i].addAttribute(TextAttribute.FONT, m_font);
m_string_paper[i].addAttribute(TextAttribute.FOREGROUND, m_paint);
}
}
m_string_view = m_string_paper;
}
use of java.text.AttributedString in project adempiere by adempiere.
the class VSchedulePanel method paint.
// setAssignmentSlots
/*************************************************************************/
/**
* Paint it
* @param g the <code>Graphics</code> object
*/
public void paint(Graphics g) {
// log.fine( "VSchedulePanel.paint", g.getClip());
Graphics2D g2D = (Graphics2D) g;
Dimension size = getPreferredSize();
Rectangle clipBounds = g2D.getClipBounds();
int w = size.width;
int h = size.height;
// Paint Background
g2D.setPaint(Color.white);
g2D.fill3DRect(1, 1, w - 2, h - 2, true);
if (// required
m_timePanel == null)
return;
int headerHeight = m_timePanel.getHeaderHeight();
// horizontal lines -
g2D.setStroke(VScheduleTimePanel.getStroke(true));
for (int i = 1; i < m_timePanel.getSlotCount(); i++) {
g2D.setPaint(Color.gray);
int yy = m_timePanel.getSlotYStart(i);
// top horiz line
g2D.drawLine(1, yy, w - 2, yy);
}
// heading and right vertical lines |
g2D.setStroke(VScheduleTimePanel.getStroke(false));
for (int i = 0; i < m_noDays; i++) {
Rectangle where = new Rectangle(i * m_dayWidth, 0, m_dayWidth, headerHeight);
if (!where.intersects(clipBounds))
continue;
// Header Background
CompiereUtils.paint3Deffect(g2D, where, false, true);
g2D.setPaint(Color.blue);
TextLayout layout = new TextLayout(getHeading(i), g2D.getFont(), g2D.getFontRenderContext());
float hh = layout.getAscent() + layout.getDescent();
// center
layout.draw(// center
g2D, // center
where.x + (m_dayWidth - layout.getAdvance()) / 2, // center
((where.height - hh) / 2) + layout.getAscent());
// line
g2D.setPaint(Color.black);
int xEnd = (i + 1) * m_dayWidth;
// right part
g2D.drawLine(xEnd, 1, xEnd, h - 1);
}
// Paint Assignments
for (int i = 0; m_slots != null && i < m_slots.length; i++) {
if (!m_where[i].intersects(clipBounds))
continue;
// Background
g2D.setColor(m_slots[i].getColor(true));
g2D.fill(m_where[i]);
// Text
String string = m_slots[i].getInfoNameDescription();
AttributedString as = new AttributedString(string);
as.addAttribute(TextAttribute.FONT, g2D.getFont());
as.addAttribute(TextAttribute.FOREGROUND, m_slots[i].getColor(false));
// Italics for Description
int startIt = string.indexOf('(');
int endIt = string.lastIndexOf(')');
if (startIt != -1 && endIt != -1)
as.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIt, endIt);
// Paint multiple lines if required
AttributedCharacterIterator aci = as.getIterator();
LineBreakMeasurer measurer = new LineBreakMeasurer(aci, g2D.getFontRenderContext());
float wrappingWidth = m_where[i].width - (2 * MARGIN);
float curY = m_where[i].y + MARGIN;
TextLayout layout = null;
int yEnd = m_where[i].y + m_where[i].height;
while (measurer.getPosition() < aci.getEndIndex() && curY < yEnd) {
layout = measurer.nextLayout(wrappingWidth);
curY += layout.getAscent();
if (curY < yEnd)
layout.draw(g2D, m_where[i].x + MARGIN, curY);
}
}
// assignments
// Paint Borders
g2D.setPaint(Color.black);
g2D.setStroke(VScheduleTimePanel.getStroke(false));
// left
g2D.drawLine(1, 1, 1, h - 1);
// top
g2D.drawLine(1, 1, w - 1, 1);
// heading line
g2D.drawLine(1, headerHeight, w - 1, headerHeight);
// Final lines
g2D.setStroke(VScheduleTimePanel.getStroke(false));
// right
g2D.drawLine(w - 1, 1, w - 1, h - 1);
// bottom line
g2D.drawLine(1, h - 1, w - 1, h - 1);
}
use of java.text.AttributedString in project adempiere by adempiere.
the class WFNode method paint.
public void paint(Graphics2D g2D) {
m_icon.paintIcon(null, g2D, 0, 0);
// Paint Text
g2D.setPaint(Color.BLACK);
Font base = new Font(null);
Font font = new Font(base.getName(), Font.ITALIC | Font.BOLD, base.getSize());
//
AttributedString aString = new AttributedString(m_node.getName(true));
aString.addAttribute(TextAttribute.FONT, font);
aString.addAttribute(TextAttribute.FOREGROUND, Color.BLACK);
AttributedCharacterIterator iter = aString.getIterator();
//
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
float width = s_size.width - m_icon.getIconWidth() - 2;
TextLayout layout = measurer.nextLayout(width);
float xPos = m_icon.getIconWidth();
float yPos = layout.getAscent() + 2;
//
layout.draw(g2D, xPos, yPos);
// 2 pt
width = s_size.width - 4;
while (measurer.getPosition() < iter.getEndIndex()) {
layout = measurer.nextLayout(width);
yPos += layout.getAscent() + layout.getDescent() + layout.getLeading();
layout.draw(g2D, 2, yPos);
}
}
use of java.text.AttributedString in project poi by apache.
the class DrawTextParagraph method getBullet.
protected DrawTextFragment getBullet(Graphics2D graphics, AttributedCharacterIterator firstLineAttr) {
BulletStyle bulletStyle = paragraph.getBulletStyle();
if (bulletStyle == null) {
return null;
}
String buCharacter;
AutoNumberingScheme ans = bulletStyle.getAutoNumberingScheme();
if (ans != null) {
buCharacter = ans.format(autoNbrIdx);
} else {
buCharacter = bulletStyle.getBulletCharacter();
}
if (buCharacter == null) {
return null;
}
String buFont = bulletStyle.getBulletFont();
if (buFont == null) {
buFont = paragraph.getDefaultFontFamily();
}
assert (buFont != null);
PlaceableShape<?, ?> ps = getParagraphShape();
PaintStyle fgPaintStyle = bulletStyle.getBulletFontColor();
Paint fgPaint;
if (fgPaintStyle == null) {
fgPaint = (Paint) firstLineAttr.getAttribute(TextAttribute.FOREGROUND);
} else {
fgPaint = new DrawPaint(ps).getPaint(graphics, fgPaintStyle);
}
float fontSize = (Float) firstLineAttr.getAttribute(TextAttribute.SIZE);
Double buSz = bulletStyle.getBulletFontSize();
if (buSz == null) {
buSz = 100d;
}
if (buSz > 0) {
fontSize *= buSz * 0.01;
} else {
fontSize = (float) -buSz;
}
AttributedString str = new AttributedString(mapFontCharset(buCharacter, buFont));
str.addAttribute(TextAttribute.FOREGROUND, fgPaint);
str.addAttribute(TextAttribute.FAMILY, buFont);
str.addAttribute(TextAttribute.SIZE, fontSize);
TextLayout layout = new TextLayout(str.getIterator(), graphics.getFontRenderContext());
DrawFactory fact = DrawFactory.getInstance(graphics);
return fact.getTextFragment(layout, str);
}
Aggregations