diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-03-19 19:55:58 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-03-19 19:55:58 +0100 |
commit | d1a8285f818eb7e5c3d6a05709ea21a808490b8c (patch) | |
tree | 326578f0505cbed07cfe60de530022822dc237ac /app/wlib/gtklib/print.c | |
parent | 16e9630b79f0a7a90c6cedb6781175bb8b337dc1 (diff) |
New upstream version 5.1.0upstream/5.1.0
Diffstat (limited to 'app/wlib/gtklib/print.c')
-rw-r--r-- | app/wlib/gtklib/print.c | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/app/wlib/gtklib/print.c b/app/wlib/gtklib/print.c index c0993f4..cad7e57 100644 --- a/app/wlib/gtklib/print.c +++ b/app/wlib/gtklib/print.c @@ -86,6 +86,8 @@ static double rBorder; /**< right margin */ static double lBorder; /**< left margin */ static double bBorder; /**< bottom margin */ +static double scale_adjust = 1.0; + static long printFormat = PRINT_LANDSCAPE; /***************************************************************************** @@ -118,7 +120,7 @@ WlibApplySettings(GtkPrintOperation *op) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } else { @@ -144,7 +146,7 @@ WlibApplySettings(GtkPrintOperation *op) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } else { @@ -193,7 +195,7 @@ WlibSaveSettings(GtkPrintOperation *op) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); g_error_free(err); gtk_dialog_run(GTK_DIALOG(dialog)); @@ -216,7 +218,7 @@ WlibSaveSettings(GtkPrintOperation *op) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); g_error_free(err); gtk_dialog_run(GTK_DIALOG(dialog)); @@ -279,21 +281,23 @@ static void setLineType( wDrawOpts opts) { cairo_t *cr = psPrint_d.printContext; - double dashLength = DASH_LENGTH; + + double dashes[] = { DASH_LENGTH, 3 }; //Reduce gap in between dashes + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); if (lineWidth < 0.0) { - lineWidth = P2I(-lineWidth)*2.0; + lineWidth = P2I(-lineWidth)*2.0/scale_adjust; } // make sure that there is a minimum line width used - if (lineWidth == 0.0) { - lineWidth = 0.1; + if (lineWidth <= 0.09) { + lineWidth = 0.1/scale_adjust; } cairo_set_line_width(cr, lineWidth); if (lineType == wDrawLineDash) { - cairo_set_dash(cr, &dashLength, 1, 0.0); + cairo_set_dash(cr, dashes, len_dashes, 0.0); } else { cairo_set_dash(cr, NULL, 0, 0.0); } @@ -537,7 +541,7 @@ void psPrintFillCircle( /** * Print a string at the given position using specified font and text size. - * The orientatoion of the y-axis in XTrackCAD is wrong for cairo. So for + * The orientation of the y-axis in XTrackCAD is wrong for cairo. So for * all other print primitives a flip operation is done. As this would * also affect the string orientation, printing a string has to be * treated differently. The starting point is transformed, then the @@ -568,7 +572,8 @@ void psPrintString( { char * cp; double x0 = (double)x, y0 = (double)y; - double text_height; + int text_height, text_width; + double ascent; cairo_t *cr; cairo_matrix_t matrix; @@ -586,10 +591,13 @@ void psPrintString( // get the current transformation matrix and transform the starting // point of the string + + cairo_save(cr); + cairo_get_matrix(cr, &matrix); + cairo_matrix_transform_point(&matrix, &x0, &y0); - cairo_save(cr); layout = pango_cairo_create_layout(cr); @@ -597,26 +605,27 @@ void psPrintString( /** \todo use a getter function instead of double conversion */ desc = pango_font_description_from_string(wlibFontTranslate(fp)); - //don't know why the size has to be reduced to 75% :-( - pango_font_description_set_size(desc, fs * PANGO_SCALE *0.75); + pango_font_description_set_size(desc, fs * PANGO_SCALE ); // render the string to a Pango layout pango_layout_set_font_description(layout, desc); pango_layout_set_text(layout, s, -1); pango_layout_set_width(layout, -1); pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); + pango_layout_get_pixel_size(layout, &text_width, &text_height); // get the height of the string pcontext = pango_cairo_create_context(cr); metrics = pango_context_get_metrics(pcontext, desc, pango_context_get_language(pcontext)); - text_height = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; - // transform the string to the correct position + ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE * scale_adjust ; + cairo_identity_matrix(cr); - cairo_translate(cr, x0 + text_height * sin(-a * M_PI / 180.0) , - y0 - text_height * cos(a * M_PI / 180.0)); + cairo_translate(cr, x0 + ((ascent + (bBorder*scale_adjust)) * sin(-a * M_PI / 180.0))+((lBorder*scale_adjust)* cos(a * M_PI / 180.0)), + y0 - ((ascent + (bBorder*scale_adjust)) * cos( a * M_PI / 180.0))+((lBorder*scale_adjust)* sin(a * M_PI / 180.0))); + cairo_rotate(cr, -a * M_PI / 180.0); // set the color @@ -633,7 +642,7 @@ void psPrintString( } /** - * Create clipping retangle. + * Create clipping rectangle. * * \param x, y IN starting position * \param w, h IN width and height of rectangle @@ -800,6 +809,7 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) cairo_surface_type_t surface_type; cairo_matrix_t matrix; + printDialog = gtk_print_unix_dialog_new(title, GTK_WINDOW(gtkMainW->gtkwin)); // load the settings @@ -848,7 +858,10 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) if (surface_type == CAIRO_SURFACE_TYPE_PDF || surface_type == CAIRO_SURFACE_TYPE_PS || surface_type == CAIRO_SURFACE_TYPE_SVG) { - psPrint_d.dpi = 72; + double p_def=600; + cairo_surface_set_fallback_resolution (psPrint_d.curPrintSurface, p_def, p_def); + psPrint_d.dpi = p_def; + scale_adjust = 72/p_def; } else { psPrint_d.dpi = (double)gtk_print_settings_get_resolution(settings); } @@ -856,11 +869,13 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) // in XTrackCAD 0,0 is top left, in cairo bottom left. This is // corrected via the following transformations. // also the translate makes sure that the drawing is rendered - // within the paper margins + // within the paper margin + + cairo_translate(psPrint_d.printContext, lBorder*72, (paperHeight-bBorder)*72 ); + + cairo_scale(psPrint_d.printContext, 1.0 * scale_adjust, -1.0 * scale_adjust); - cairo_scale(psPrint_d.printContext, 1.0, -1.0); - cairo_translate(psPrint_d.printContext, lBorder * psPrint_d.dpi, - -(paperHeight-bBorder) *psPrint_d.dpi); + //cairo_translate(psPrint_d.printContext, 0, -paperHeight* psPrint_d.dpi); WlibSaveSettings(NULL); } @@ -900,7 +915,7 @@ doPrintJobFinished(GtkPrintJob *job, void *data, GError *err) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); } } |