[Gtk-osx-users] GTK (cairo) rendering to PDF/printer does not show text



Not sure if it is a development issue, or a user issue.

Our application uses Cairo to draw directly into a cairo context the following page:

http://www.inksystemsinc.com/images/gtkodie/ODIE%20App%20window.png

However when we print this to PDF or a printer device we get:

http://www.inksystemsinc.com/images/gtkodie/ODIE%20Printed%20PDF%20no%20selection.png

and it does not happen all the time. Only on rare instances. I have tried to look for invalid strings in the text, and I am in the process of looking for buffer overruns that could affect the output. But I am confused as to why it displays on screen, but not in a PDF or printer. The actual drawing routing is the same exact function, it is simply called from the different callbacks form Draw and Print sending to the function the ciaro context and sizes.

The reason I think this has to be Ciaro to PDF issues, is the following images, which is the blank PDF with all the text highlighted. Notice that the text is there, it is either white or in some glyth PDF/printer can not draw, but that does not make any sense since it only happens on 1 out of 1000 formulas. More importantly it always happens with the same formulas. SY 17201 does not have any problems.

http://www.inksystemsinc.com/images/gtkodie/ODIE%20PDF%20text%20Selected.png

To make things even more strange, this all seems to work fine when I compile using VC 2010 Express on Windows XP 32it. It only seems to be happening on the OS X side. I have not tried native Linux.

Any assistance would be greatly appreciated :)
OS X 10.6.7 xCode 4 GTK 2.28
Shawn

Code:

isi_display_cairo_formula gets called both from the onDraw Callback and onPrint callbacks, it creates a context for DarwingArea or from the printer and passes it through.


void
 isi_display_cairo_formula(IsiDisplay *self, cairo_t *cr, IsiComponent *c, guint page_nr, guint x, guint y, guint width, guint height)
{


....

    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);

    /* Set start of the advance */
    advanced2 = advanced =  0.16  * ymultip;


    /* Display formula information */
    pango_font_description_set_absolute_size(font_description, 0.015 * PANGO_SCALE);
    pango_layout_set_font_description(layout,font_description);
    graphics_draw_props(cr,   layout, font_description, 0.016, 0.015,(x + 0.53470588) * xmultip ,( y + (0.1044545  - 0.01572)) * ymultip,
                                        rmc, voc,  gravity, stability, strength, tack);

    /* Display the formulation */   
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
    pango_font_description_set_absolute_size(font_description, 0.017 * PANGO_SCALE);
    pango_layout_set_font_description(layout,font_description);

    g_object_get((GObject*)c,"formulation",&list,NULL);

    if(list != NULL){
           
        fline_rows = g_list_length(list->rows);

        if(page_nr <= (guint)(fline_rows / 20) ){
            advanced2 =  advanced = graphics_draw_formula_lines(cr,  layout, font_description, xmultip,ymultip, 0.030, 0.017,  0.03147272, 0.15034955 , list, page_nr);}
       
    }


....

}


And the

/**
 * graphics_draw_formula_lines:
 * @cr: cairo_t context to draw into
 * @xm: scale adjustment in x
 * @ym: scale adjustment in y
 * @x: x location on the context
 * @y: y location on the context
 * @line_width: width the line
 * @font_size: Size of font
 * @list: An #IsiList whos row pointer is of type #IsiBatchLine
 *
 * Renders to a cairo context the formulation lines for a component.
 *
 * Returns: the amount of y used in rendering
 */
gdouble 
 graphics_draw_formula_lines(cairo_t *cr,  PangoLayout *layout, PangoFontDescription *font_description,
                gdouble xm, gdouble ym,
                     gdouble line_width, gdouble font_size, gdouble x, gdouble y,
                         IsiList *list, guint page_nr)
{
 

   
   
    IsiFormulaLine *fl;
    gchar *line_description = NULL;
   
   
    guint num_rows,i;            /* number of order lines to draw */
    gchar buff[255];
    gdouble advanced = 0.0f;
    gdouble tperc = 0.0f;
    gdouble tlbs = 0.0f;
    gdouble albs = 0.0f;
    guint num_lines = 20;        /* ALways plus 1 for header */
    gdouble box_size = 0.937786f;
    gdouble ypadding = 0.0f;
   
    guint num_cols = 8;        /* ALways plus 1 for header */
    gdouble row_width = 0.0f;
    gdouble row_half_width = 0.0f;
    guint line_start = 0;
    guint line_end = 0;
   
    const double dash_pattern[5] = {0.005,0.005,0.005,0.005,0.005};
   
   
    /* Sanity Check */
    g_return_if_fail(cr != NULL);
    g_return_if_fail(layout != NULL);
    g_return_if_fail(font_description != NULL);
   
    /* Local Check */
    g_return_val_if_fail( list != NULL, 0.0);
   
   
    num_rows = g_list_length(list->rows);
   
    line_start = (page_nr) * num_lines;
    line_end = line_start + num_lines;
   
   
    /* Get row width and set start leaving room for labels at begining of each line*/
    row_width = box_size/num_cols;
    row_half_width = box_size/(num_cols*2);
   
    ypadding = ((line_width - (font_size*0.5))/2);
   
    /* Defualt settings */
    //pango_font_description_set_absolute_size(font_description, font_size * PANGO_SCALE);
    //pango_layout_set_font_description(layout,font_description);
    pango_layout_set_alignment (layout,PANGO_ALIGN_LEFT);
    pango_layout_set_width(layout, row_width * PANGO_SCALE);
    pango_layout_set_attributes(layout,NULL); /* CLEAR BEFORE WE USE TEXT AGAIN */
   

    if(line_start > num_rows){ return 0.0;}
    if(line_end > num_rows) { line_end = num_rows;}
   
    for (i=line_start;i<line_end;i++){

//        if (i == 3) i++;
       
        pango_layout_set_attributes(layout,NULL); /* CLEAR BEFORE WE USE TEXT AGAIN */

        /* DEBUG ONLY */
    //    cairo_rectangle(cr, (x) * xm , (y + ( (i-line_start) * line_width)) * ym,
    //                    box_size,line_width);
    //    cairo_stroke(cr);
       
        /* Draw the amount ordered */
        fl = (IsiFormulaLine*) g_list_nth_data(list->rows,i);
       
       
        tperc +=fl->percentage;
       
       
        if(strncmp(fl->aid,"MSG",3) == 0){
           
            cairo_set_source_rgba(cr, 0.8, 0.0, 0.0, 1.0);
            pango_layout_set_width(layout, row_width * PANGO_SCALE);
            pango_layout_set_alignment (layout,PANGO_ALIGN_LEFT);
           
            cairo_move_to(cr, (x +     (row_half_width * 0.4))  * xm , (y + ( (i-line_start) * line_width) + ypadding) * ym );
            pango_layout_set_text(layout, " *******",-1);
            pango_cairo_show_layout(cr,layout);
           
            pango_layout_set_width(layout, row_width * 3 * PANGO_SCALE);
            cairo_move_to(cr, (x +     (row_width * 1)) * xm , (y + (  (i-line_start) * line_width) + ypadding) * ym );
            g_sprintf(buff, " %s     ********",fl->description);
            pango_layout_set_text(layout, buff,-1);
            pango_cairo_show_layout(cr,layout);
           
           
        } else {
           
            cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
            pango_layout_set_width(layout, row_width * PANGO_SCALE);
            pango_layout_set_alignment (layout,PANGO_ALIGN_LEFT);
           
            /* Alpha Numeric of item */
            cairo_move_to(cr, (x +     (row_half_width * 0.4)) * xm , (y + (  (i-line_start) * line_width) + ypadding) * ym );
            g_sprintf(buff, " %s-%d",fl->aid,fl->nid);
            pango_layout_set_text(layout, buff,-1);
            pango_cairo_show_layout(cr,layout);
           
            pango_layout_set_width(layout, row_width * 3 * PANGO_SCALE);


            if(fl->description != NULL){
               
                /* Form description of the line */
                if (fl->hold_percentage != 0.00f){
                   
                    /* Escape any specail charactors in the line */
                    line_description = g_strescape(fl->description,NULL);

                    cairo_move_to(cr, (x +     (row_width * 1)) * xm , (y + (  (i-line_start) * line_width) + ypadding) * ym );
                    g_sprintf(buff, "%s  <span color=\"blue\" size=\"small\">( hold %.2f &#37; )</span>",line_description,fl->hold_percentage);

                   

                    pango_layout_set_markup(layout, buff,-1);
                    pango_cairo_show_layout(cr,layout);

                    free(line_description);
                   
                } else {
                   
                    cairo_move_to(cr, (x +     (row_width * 1)) * xm , (y + (  (i-line_start) * line_width) + ypadding) * ym );
                    g_sprintf(buff, "%s",fl->description);

                    /* Escape any specail charactors in the line */
                    line_description = g_strescape(buff,NULL);

                   
                    pango_layout_set_attributes(layout,NULL); /* CLEAR BEFORE WE USE TEXT AGAIN */
                    pango_layout_set_text(layout, line_description,35);
                    pango_cairo_show_layout(cr,layout);

                    free(line_description);

                   
                }

            }
               
            pango_layout_set_alignment (layout,PANGO_ALIGN_RIGHT);
            pango_layout_set_width(layout, row_width * PANGO_SCALE);
            /* Alpha Numeric of item */
            cairo_move_to(cr, (x +     (row_half_width * 7.5)) * xm , (y + (  (i-line_start) * line_width) + ypadding) * ym );
            g_sprintf(buff, "%5.3f",fl->percentage);
            pango_layout_set_text(layout, buff,-1);
            pango_cairo_show_layout(cr,layout);
           
           
        }
       
    }
   
   
    /* Left Align for numeric text */
    cairo_set_source_rgba(cr, 0.0, 0.3, 0.3, 1.0);
    pango_layout_set_width(layout, row_width * PANGO_SCALE);
    pango_layout_set_alignment (layout,PANGO_ALIGN_RIGHT);
   
   
    /* Defualt settings */
    pango_font_description_set_absolute_size(font_description, font_size * 1.3 * PANGO_SCALE);
    pango_layout_set_font_description(layout,font_description);
   
    ypadding = ((line_width - (font_size))/2);
   
    /* Percentage of the line */
    cairo_move_to(cr, (x +     (row_half_width * 7.5)) * xm , (y + (  (num_lines) * line_width) + ypadding) * ym );
    g_sprintf(buff, "%5.3f",tperc);
    pango_layout_set_text(layout, buff,-1);
    pango_cairo_show_layout(cr,layout);
   
   
    /* calculate lower bounding point */
    advanced = ( y + ( ((gdouble)line_start - line_width) * line_width) );

 

return advanced; }












[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]