use of java.awt.geom.Point2D in project adempiere by adempiere.
the class ImageElement method paint.
/**
* Paint Image
* @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) {
if (m_image == null)
return;
// Position
Point2D.Double location = getAbsoluteLocation(pageStart);
int x = (int) location.x;
if (MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight.equals(p_FieldAlignmentType))
x += p_maxWidth - p_width;
else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Center.equals(p_FieldAlignmentType))
x += (p_maxWidth - p_width) / 2;
int y = (int) location.y;
// map a scaled and shifted version of the image to device space
AffineTransform transform = new AffineTransform();
transform.translate(x, y);
transform.scale(m_scaleFactor, m_scaleFactor);
g2D.drawImage(m_image, transform, this);
}
use of java.awt.geom.Point2D 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.awt.geom.Point2D in project adempiere by adempiere.
the class HTMLElement method paint.
// calculateSize
/*************************************************************************
/**
* 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) {
// 36.0/137.015625, Clip=java.awt.Rectangle[x=0,y=0,width=639,height=804], Translate=1.0/56.0, Scale=1.0/1.0, Shear=0.0/0.0
// log.finest( "HTMLElement.paint", 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);
// log.finest( "HTMLElement.paint - PageStart=" + pageStart + ", Location=" + location);
//
Rectangle allocation = m_renderer.getAllocation();
g2D.translate(location.x, location.y);
m_renderer.paint(g2D, allocation);
g2D.translate(-location.x, -location.y);
}
use of java.awt.geom.Point2D in project poi by apache.
the class SplineCollector method addToPath.
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
// ok, we have the start, and all knots... do something with this
Point2D last = path.getCurrentPoint();
// create a control path and knots
ControlPath controlPath = new ControlPath();
ValueVector knots = new ValueVector(_knots.size() + 3);
double firstKnot = _start.getB();
double lastKnot = _start.getC();
int degree = _start.getD();
// first/second knot
knots.add(firstKnot);
knots.add(_start.getA());
// first/second control point
controlPath.addPoint(PointFactory.create(last.getX(), last.getY()));
controlPath.addPoint(PointFactory.create(_start.getX(), _start.getY()));
// middle knots/control points
for (SplineKnot knot : _knots) {
knots.add(knot.getA());
controlPath.addPoint(PointFactory.create(knot.getX(), knot.getY()));
}
// last knot
knots.add(lastKnot);
ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath, knots, null, degree);
path.append(shape, true);
}
use of java.awt.geom.Point2D in project poi by apache.
the class NURBSTo method addToPath.
@Override
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel())
return;
Point2D last = path.getCurrentPoint();
// A NURBS formula: knotLast, degree, xType, yType, x1, y1, knot1,
// weight1, ..
String formula = getE().trim();
if (!formula.startsWith("NURBS(") || !formula.endsWith(")"))
throw new POIXMLException("Invalid NURBS formula: " + formula);
String[] components = formula.substring(6, formula.length() - 1).split(",");
if (components.length < 8)
throw new POIXMLException("Invalid NURBS formula (not enough arguments)");
if ((components.length - 4) % 4 != 0)
throw new POIXMLException("Invalid NURBS formula -- need 4 + n*4 arguments, got " + components.length);
double lastControlX = getX();
double lastControlY = getY();
double secondToLastKnot = getA();
double lastWeight = getB();
double firstKnot = getC();
double firstWeight = getD();
double lastKnot = Double.parseDouble(components[0].trim());
int degree = Integer.parseInt(components[1].trim());
int xType = Integer.parseInt(components[2].trim());
int yType = Integer.parseInt(components[3].trim());
double xScale = 1;
double yScale = 1;
if (xType == 0)
xScale = parent.getWidth();
if (yType == 0)
yScale = parent.getHeight();
// setup first knots/weights/control point
ControlPath controlPath = new ControlPath();
ValueVector knots = new ValueVector();
ValueVector weights = new ValueVector();
knots.add(firstKnot);
weights.add(firstWeight);
controlPath.addPoint(PointFactory.create(last.getX(), last.getY()));
// iterate get knots/weights
int sets = (components.length - 4) / 4;
for (int i = 0; i < sets; i++) {
double x1 = Double.parseDouble(components[4 + i * 4 + 0].trim());
double y1 = Double.parseDouble(components[4 + i * 4 + 1].trim());
double k = Double.parseDouble(components[4 + i * 4 + 2].trim());
double w = Double.parseDouble(components[4 + i * 4 + 3].trim());
controlPath.addPoint(PointFactory.create(x1 * xScale, y1 * yScale));
knots.add(k);
weights.add(w);
}
// last knots/weights/control point
knots.add(secondToLastKnot);
knots.add(lastKnot);
weights.add(lastWeight);
controlPath.addPoint(PointFactory.create(lastControlX, lastControlY));
ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath, knots, weights, degree);
path.append(shape, true);
}
Aggregations