Issue #2318 Added OVERLINE,UNDERLINE, and STRIKETHROUGH text styles

Change-Id: I8762cb2385a89941936f37e6fb65dc324d5af0e5

Former-commit-id: 6ec6a0cd016a240f9e91baef4d16ba01f9676049
This commit is contained in:
Max Schenkelberg 2013-09-16 12:53:34 -05:00
parent ab9a38f7ce
commit c3f6193618
2 changed files with 60 additions and 28 deletions

View file

@ -79,7 +79,7 @@ public interface IGraphicsTarget extends IImagingExtension {
/** Defines text characteristics */
public static enum TextStyle {
NORMAL, BLANKED, BOXED, WORD_WRAP, DROP_SHADOW, OUTLINE
NORMAL, BLANKED, BOXED, WORD_WRAP, DROP_SHADOW, OUTLINE, UNDERLINE, OVERLINE, STRIKETHROUGH;
};
/**

View file

@ -1854,9 +1854,12 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
// This loop just draws the box or a blank rectangle.
for (DrawableString dString : parameters) {
float[] rotatedPoint = null;
if (dString.textStyle == TextStyle.BOXED
|| dString.textStyle == TextStyle.BLANKED) {
switch (dString.textStyle) {
case BOXED:
case BLANKED:
case UNDERLINE:
case OVERLINE:
case STRIKETHROUGH:
double yPos = dString.basics.y;
VerticalAlignment verticalAlignment = dString.verticallAlignment;
double fontPercentage = this
@ -1874,6 +1877,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
double scaleX = stringScaleX;
double scaleY = stringScaleY;
float[] rotatedPoint = null;
if (dString.rotation != 0.0) {
rotatedPoint = getUpdatedCoordinates(
new java.awt.Rectangle(0, 0, 0, 0),
@ -1897,18 +1901,6 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
dString.basics.x, yPos, dString.basics.z,
dString.rotation, fontPercentage);
gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL);
if (dString.textStyle == TextStyle.BOXED
&& dString.boxColor != null) {
gl.glColor4d(dString.boxColor.red / 255.0,
dString.boxColor.green / 255.0,
dString.boxColor.blue / 255.0, alpha);
} else {
gl.glColor4d(backgroundColor.red / 255.0,
backgroundColor.green / 255.0,
backgroundColor.blue / 255.0, alpha);
}
double width = textBounds.getWidth();
double height = textBounds.getHeight();
double diff = height + textBounds.getY();
@ -1918,38 +1910,78 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
double x2 = xy[0] + width + scaleX;
double y2 = (xy[1] - diff) + height + scaleY;
gl.glRectd(x1, y2, x2, y1);
if (dString.textStyle == TextStyle.BOXED
|| dString.textStyle == TextStyle.BLANKED) {
gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL);
if (dString.textStyle == TextStyle.BOXED
&& dString.boxColor != null) {
gl.glColor4d(dString.boxColor.red / 255.0,
dString.boxColor.green / 255.0,
dString.boxColor.blue / 255.0, alpha);
} else {
gl.glColor4d(backgroundColor.red / 255.0,
backgroundColor.green / 255.0,
backgroundColor.blue / 255.0, alpha);
}
gl.glRectd(x1, y2, x2, y1);
}
if (dString.textStyle == TextStyle.BOXED
|| dString.textStyle == TextStyle.UNDERLINE
|| dString.textStyle == TextStyle.OVERLINE
|| dString.textStyle == TextStyle.STRIKETHROUGH) {
gl.glPolygonMode(GL.GL_BACK, GL.GL_LINE);
if (dString.textStyle == TextStyle.BOXED) {
RGB color = dString.getColors()[c];
if (color == null) {
color = DEFAULT_LABEL_COLOR;
}
gl.glPolygonMode(GL.GL_BACK, GL.GL_LINE);
gl.glColor4d(color.red / 255.0,
color.green / 255.0, color.blue / 255.0,
alpha);
gl.glLineWidth(2);
gl.glRectd(x1, y2, x2, y1);
if (dString.textStyle == TextStyle.BOXED) {
gl.glLineWidth(2);
gl.glRectd(x1, y2, x2, y1);
} else {
gl.glLineWidth(1);
double percent;
if (dString.textStyle == TextStyle.UNDERLINE) {
percent = .2;
} else if (dString.textStyle == TextStyle.OVERLINE) {
percent = 1.;
} else { // TextStyle.STRIKETHROUGH
percent = .5;
}
double lineY = y1 + (y2 - y1) * percent;
gl.glBegin(GL.GL_LINES);
gl.glVertex2d(x1, lineY);
gl.glVertex2d(x2, lineY);
gl.glEnd();
}
}
gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL);
if (verticalAlignment == VerticalAlignment.TOP) {
yPos += textBounds.getHeight();
} else {
yPos -= textBounds.getHeight();
}
}
}
if (rotatedPoint != null) {
gl.glTranslated(rotatedPoint[0], rotatedPoint[1], 0.0);
gl.glRotated(-dString.rotation, 0.0, 0.0, 1.0);
gl.glTranslated(-rotatedPoint[0], -rotatedPoint[1], 0.0);
if (rotatedPoint != null) {
gl.glTranslated(rotatedPoint[0], rotatedPoint[1], 0.0);
gl.glRotated(-dString.rotation, 0.0, 0.0, 1.0);
gl.glTranslated(-rotatedPoint[0], -rotatedPoint[1], 0.0);
}
break;
default:
break;
}
}
gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL);
IFont font = null;
double magnification = -1.0;
double fontPercentage = -1.0;