Commit 5e9474b6 authored by Claes Sjofors's avatar Claes Sjofors

Ge rotation of texts in java export

parent 981fa508
...@@ -2863,7 +2863,8 @@ void GlowExportJBean::arc( double x0, double y0, double width, double height, ...@@ -2863,7 +2863,8 @@ void GlowExportJBean::arc( double x0, double y0, double width, double height,
void GlowExportJBean::text( int x0, int y0, char *text, void GlowExportJBean::text( int x0, int y0, char *text,
glow_eDrawType drawtype, glow_eDrawType color_drawtype, int bold, glow_eDrawType drawtype, glow_eDrawType color_drawtype, int bold,
int idx, glow_eExportPass pass, int *shape_cnt, int node_cnt, ofstream& fp) int idx, int rotate, glow_eExportPass pass, int *shape_cnt, int node_cnt,
ofstream& fp)
{ {
double dim_x0, dim_x1, dim_y0, dim_y1; double dim_x0, dim_x1, dim_y0, dim_y1;
...@@ -2908,6 +2909,29 @@ void GlowExportJBean::text( int x0, int y0, char *text, ...@@ -2908,6 +2909,29 @@ void GlowExportJBean::text( int x0, int y0, char *text,
// " g.setColor(Color.black);" << endl << // " g.setColor(Color.black);" << endl <<
" g.setFont(new Font(\"Helvetica\", Font." << bold_str << ", " << " g.setFont(new Font(\"Helvetica\", Font." << bold_str << ", " <<
text_size << "));" << endl; text_size << "));" << endl;
if ( 45.0 <= rotate && rotate < 135.0) {
fp <<
" save_tmp = g.getTransform();" << endl <<
" g.rotate( - Math.PI * 3/ 2," <<
x0 - int(dim_x0) + glow_cJBean_Offset << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << ");" << endl;
}
else if ( 135.0 <= rotate && rotate < 225.0) {
fp <<
" save_tmp = g.getTransform();" << endl <<
" g.rotate( - Math.PI," <<
x0 - int(dim_x0) + glow_cJBean_Offset << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << ");" << endl;
}
else if ( 225.0 <= rotate && rotate < 315.0) {
fp <<
" save_tmp = g.getTransform();" << endl <<
" g.rotate( - Math.PI / 2," <<
x0 - int(dim_x0) + glow_cJBean_Offset << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << ");" << endl;
}
if ( ((GrowCtx *)ctx)->translate_on) if ( ((GrowCtx *)ctx)->translate_on)
fp << fp <<
" g.drawString( JopLang.transl(\"" << str_cnv( text) << "\")," << " g.drawString( JopLang.transl(\"" << str_cnv( text) << "\")," <<
...@@ -2918,6 +2942,12 @@ void GlowExportJBean::text( int x0, int y0, char *text, ...@@ -2918,6 +2942,12 @@ void GlowExportJBean::text( int x0, int y0, char *text,
" g.drawString( \"" << str_cnv( text) << "\"," << " g.drawString( \"" << str_cnv( text) << "\"," <<
x0 - int(dim_x0) + glow_cJBean_Offset << ", " << x0 - int(dim_x0) + glow_cJBean_Offset << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << ");" << endl; y0 - int(dim_y0) + glow_cJBean_Offset << ");" << endl;
if ( 45.0 <= rotate && rotate < 315.0) {
fp <<
" g.setTransform( save_tmp);" << endl;
}
break; break;
} }
default: default:
...@@ -3014,6 +3044,8 @@ void GlowExportJBean::annot( int x0, int y0, int number, ...@@ -3014,6 +3044,8 @@ void GlowExportJBean::annot( int x0, int y0, int number,
case glow_eExportPass_Draw: case glow_eExportPass_Draw:
{ {
char adjustmentstr[200]; char adjustmentstr[200];
char adjustmentstr_vert[200];
char adjustmentstr_horiz[200];
switch ( adjustment) { switch ( adjustment) {
case glow_eAdjustment_Right: case glow_eAdjustment_Right:
if ( !frc_created) { if ( !frc_created) {
...@@ -3029,7 +3061,8 @@ void GlowExportJBean::annot( int x0, int y0, int number, ...@@ -3029,7 +3061,8 @@ void GlowExportJBean::annot( int x0, int y0, int number,
fp << fp <<
" FontRenderContext frc = g.getFontRenderContext();" << endl; " FontRenderContext frc = g.getFontRenderContext();" << endl;
} }
sprintf( adjustmentstr, "- (float)g.getFont().getStringBounds(annot%d, frc).getWidth()/2", number); sprintf( adjustmentstr_vert, "- (float)g.getFont().getStringBounds(annot%d, frc).getWidth()/2", number);
sprintf( adjustmentstr_horiz, "- (float)g.getFont().getStringBounds(annot%d, frc).getWidth()/2", number);
break; break;
default: default:
strcpy( adjustmentstr, ""); strcpy( adjustmentstr, "");
...@@ -3044,25 +3077,74 @@ void GlowExportJBean::annot( int x0, int y0, int number, ...@@ -3044,25 +3077,74 @@ void GlowExportJBean::annot( int x0, int y0, int number,
//" g.setColor(Color.black);" << endl << //" g.setColor(Color.black);" << endl <<
" g.setFont( annot" << number << "Font);" << endl << " g.setFont( annot" << number << "Font);" << endl <<
" save_tmp = g.getTransform();" << endl; " save_tmp = g.getTransform();" << endl;
if ( antialiasing_on) if ( antialiasing_on) {
fp << if ( adjustment == glow_eAdjustment_Center) {
fp <<
" if ( (45.0 <= rotate && rotate < 135.0) || (225.0 <= rotate && rotate < 315.0)) {" << endl <<
" g.transform( AffineTransform.getScaleInstance( original_height/width *" << endl <<
" height/original_width * 0.75, 1));" << endl <<
" if ( annot" << number << " != null)" << endl <<
" g.drawString( annot" << number << ", " <<
x0 - int(dim_x0) + glow_cJBean_Offset <<
" * original_height / width * height / original_width" << adjustmentstr_vert << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << "F);" << endl <<
" }" << endl <<
" else {" << endl <<
" g.transform( AffineTransform.getScaleInstance( original_width/width *" << endl <<
" height/original_height * 0.75, 1));" << endl <<
" if ( annot" << number << " != null)" << endl <<
" g.drawString( annot" << number << ", " <<
x0 - int(dim_x0) + glow_cJBean_Offset <<
" * original_height / height * width / original_width" << adjustmentstr_horiz << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << "F);" << endl <<
" }" << endl;
}
else {
fp <<
" g.transform( AffineTransform.getScaleInstance( original_width/width *" << endl << " g.transform( AffineTransform.getScaleInstance( original_width/width *" << endl <<
" height/original_height * 0.75, 1));" << endl << " height/original_height * 0.75, 1));" << endl <<
" if ( annot" << number << " != null)" << endl << " if ( annot" << number << " != null)" << endl <<
" g.drawString( annot" << number << ", " << " g.drawString( annot" << number << ", " <<
x0 - int(dim_x0) + glow_cJBean_Offset << x0 - int(dim_x0) + glow_cJBean_Offset <<
" * original_height / height * width / original_width" << adjustmentstr << ", " << " * original_height / height * width / original_width" << adjustmentstr << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << "F);" << endl; y0 - int(dim_y0) + glow_cJBean_Offset << "F);" << endl;
else }
fp << }
else {
if ( adjustment == glow_eAdjustment_Center) {
fp <<
" if ( (45.0 <= rotate && rotate < 135.0) || (225.0 <= rotate && rotate < 315.0)) {" << endl <<
" g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);" << endl <<
" g.transform( AffineTransform.getScaleInstance( original_width/height *" << endl <<
" width/original_height, 1));" << endl <<
" if ( annot" << number << " != null)" << endl <<
" g.drawString( annot" << number << ", " <<
x0 - int(dim_x0) + glow_cJBean_Offset <<
" * original_height / width * height / original_width" << adjustmentstr_vert << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << "F);" << endl <<
" } else {" << endl <<
" g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);" << endl <<
" g.transform( AffineTransform.getScaleInstance( original_width/width *" << endl <<
" height/original_height, 1));" << endl <<
" if ( annot" << number << " != null)" << endl <<
" g.drawString( annot" << number << ", " <<
x0 - int(dim_x0) + glow_cJBean_Offset <<
" * original_height / height * width / original_width" << adjustmentstr_horiz << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << "F);" << endl <<
" }" << endl;
}
else {
fp <<
" g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);" << endl << " g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);" << endl <<
" g.transform( AffineTransform.getScaleInstance( original_width/width *" << endl << " g.transform( AffineTransform.getScaleInstance( original_width/width *" << endl <<
" height/original_height, 1));" << endl << " height/original_height, 1));" << endl <<
" if ( annot" << number << " != null)" << endl << " if ( annot" << number << " != null)" << endl <<
" g.drawString( annot" << number << ", " << " g.drawString( annot" << number << ", " <<
x0 - int(dim_x0) + glow_cJBean_Offset << x0 - int(dim_x0) + glow_cJBean_Offset <<
" * original_height / height * width / original_width" << adjustmentstr << ", " << " * original_height / height * width / original_width" << adjustmentstr << ", " <<
y0 - int(dim_y0) + glow_cJBean_Offset << "F);" << endl; y0 - int(dim_y0) + glow_cJBean_Offset << "F);" << endl;
}
}
fp << fp <<
" g.setTransform( save_tmp);" << endl; " g.setTransform( save_tmp);" << endl;
break; break;
......
...@@ -86,7 +86,8 @@ class GlowExportJBean { ...@@ -86,7 +86,8 @@ class GlowExportJBean {
glow_eExportPass pass, int *shape_cnt, int node_cnt, ofstream& fp); glow_eExportPass pass, int *shape_cnt, int node_cnt, ofstream& fp);
void text( int x0, int y0, char *text, void text( int x0, int y0, char *text,
glow_eDrawType drawtype, glow_eDrawType color_drawtype, int bold, glow_eDrawType drawtype, glow_eDrawType color_drawtype, int bold,
int idx, glow_eExportPass pass, int *shape_cnt, int node_cnt, ofstream& fp); int idx, int rotate, glow_eExportPass pass, int *shape_cnt, int node_cnt,
ofstream& fp);
void annot( int x0, int y0, int number, void annot( int x0, int y0, int number,
glow_eDrawType drawtype, glow_eDrawType text_drawtype, int bold, glow_eDrawType drawtype, glow_eDrawType text_drawtype, int bold,
glow_eAdjustment adjustment, int idx, glow_eExportPass pass, glow_eAdjustment adjustment, int idx, glow_eExportPass pass,
......
...@@ -705,7 +705,7 @@ void GrowText::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, voi ...@@ -705,7 +705,7 @@ void GrowText::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, voi
if ( strcmp( text, "")) { if ( strcmp( text, "")) {
if ( highl || (hot && !node) || adjustment != glow_eAdjustment_Left) { if ( highl || (hot && !node) || adjustment != glow_eAdjustment_Left) {
ctx->gdraw->get_text_extent( text, strlen(text), ldraw_type, max( 0, idx), lfont, ctx->gdraw->get_text_extent( text, strlen(text), ldraw_type, max( 0, idx), lfont,
&z_width, &z_height, &z_descent, tsize, rot); &z_width, &z_height, &z_descent, tsize, rot);
switch ( adjustment) { switch ( adjustment) {
case glow_eAdjustment_Left: case glow_eAdjustment_Left:
...@@ -1026,24 +1026,75 @@ void GrowText::export_javabean( GlowTransform *t, void *node, ...@@ -1026,24 +1026,75 @@ void GrowText::export_javabean( GlowTransform *t, void *node,
glow_eExportPass pass, int *shape_cnt, int node_cnt, int in_nc, ofstream &fp) glow_eExportPass pass, int *shape_cnt, int node_cnt, int in_nc, ofstream &fp)
{ {
int x1, y1; int x1, y1;
int z_width, z_height, z_descent;
int rot;
int bold; int bold;
double trf_scale = trf.vertical_scale( t); double trf_scale = trf.vertical_scale( t);
int idx = int( trf_scale * ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor * (text_size +4) - 4); int idx = int( trf_scale * ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor * (text_size +4) - 4);
idx = min( idx, DRAW_TYPE_SIZE-1); idx = min( idx, DRAW_TYPE_SIZE-1);
double tsize = trf_scale * ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor * (8+2*text_size);
glow_eFont lfont;
glow_eDrawType ldraw_type;
if ( node && ((GrowNode *)node)->text_font != glow_eFont_No) {
lfont = ((GrowNode *)node)->text_font;
ldraw_type = ((GrowNode *)node)->text_type;
}
else {
lfont = font;
ldraw_type = draw_type;
}
if (!t) { if (!t) {
x1 = int( trf.x( p.x, p.y) * ctx->mw.zoom_factor_x) - ctx->mw.offset_x; x1 = int( trf.x( p.x, p.y) * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
y1 = int( trf.y( p.x, p.y) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y; y1 = int( trf.y( p.x, p.y) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
rot = (int) trf.rot();
} }
else { else {
x1 = int( trf.x( t, p.x, p.y) * ctx->mw.zoom_factor_x) - ctx->mw.offset_x; x1 = int( trf.x( t, p.x, p.y) * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
y1 = int( trf.y( t, p.x, p.y) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y; y1 = int( trf.y( t, p.x, p.y) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
rot = (int) trf.rot( t);
} }
if ( adjustment == glow_eAdjustment_Center)
rot = rot < 0 ? rot % 360 + 360 : rot % 360;
else
rot = 0;
ctx->gdraw->get_text_extent( text, strlen(text), ldraw_type, max( 0, idx), lfont,
&z_width, &z_height, &z_descent, tsize, rot);
switch ( adjustment) {
case glow_eAdjustment_Left:
break;
case glow_eAdjustment_Right:
x1 -= z_width;
break;
case glow_eAdjustment_Center:
switch ( rot) {
case 90:
x1 -= z_width / 2 - z_descent;
y1 -= z_height / 2;
break;
case 270:
x1 += z_width / 2 - z_descent;
y1 += z_height / 2;
break;
case 180:
x1 += z_width / 2;
y1 -= z_height / 2 - z_descent;
break;
default:
x1 -= z_width / 2;
y1 += z_height / 2 - z_descent;
}
break;
}
bold = (draw_type == glow_eDrawType_TextHelveticaBold); bold = (draw_type == glow_eDrawType_TextHelveticaBold);
ctx->export_jbean->text( x1, y1, text, ctx->export_jbean->text( x1, y1, text,
draw_type, color_drawtype, bold, idx, pass, shape_cnt, node_cnt, fp); draw_type, color_drawtype, bold, idx, rot,
pass, shape_cnt, node_cnt, fp);
} }
void GrowText::flip( double x0, double y0, glow_eFlipDirection dir) void GrowText::flip( double x0, double y0, glow_eFlipDirection dir)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment