segmentation fault when using pango inside evince backend



Hello.

I am developing evince backend for hwp document file.
I want to apply pango layout to evince hwp backend.

so, I tried to apply "Example 1. Using Pango with Cairo"
(https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html)
to SAMPLE evince backend and EXAMPLE library.

/* Example 1. Using Pango with Cairo */
/* https://developer.gnome.org/pango/1.34/pango-Cairo-Rendering.html */
#include <math.h>
#include <pango/pangocairo.h>
static void
draw_text (cairo_t *cr)
{
#define RADIUS 150
#define N_WORDS 10
#define FONT "Sans Bold 27"
  PangoLayout *layout;
  PangoFontDescription *desc;
  int i;
  /* Center coordinates on the middle of the region we are drawing
   */
  cairo_translate (cr, RADIUS, RADIUS);
  /* Create a PangoLayout, set the font and text */
  layout = pango_cairo_create_layout (cr);
  pango_layout_set_text (layout, "Text", -1);
  desc = pango_font_description_from_string (FONT);
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);
  /* Draw the layout N_WORDS times in a circle */
  for (i = 0; i < N_WORDS; i++)
    {
      int width, height;
      double angle = (360. * i) / N_WORDS;
      double red;
      cairo_save (cr);
      /* Gradient from red at angle == 60 to blue at angle == 240 */
      red   = (1 + cos ((angle - 60) * G_PI / 180.)) / 2;
      cairo_set_source_rgb (cr, red, 0, 1.0 - red);
      cairo_rotate (cr, angle * G_PI / 180.);
      /* Inform Pango to re-layout the text with the new transformation */
      pango_cairo_update_layout (cr, layout);
      pango_layout_get_size (layout, &width, &height);
      cairo_move_to (cr, - ((double)width / PANGO_SCALE) / 2, - RADIUS);
      pango_cairo_show_layout (cr, layout);
      cairo_restore (cr);
    }
  /* free the layout object */
  g_object_unref (layout);
}

gboolean example_page_render (ExamplePage *page, cairo_t *cr)
{
    g_return_val_if_fail (EXAMPLE_IS_PAGE (page), FALSE);
    draw_text (cr);
    return TRUE;
}

then opened the sample text file from the terminal with evince
but segmentation fault occurred intermittently.

I cannot understand the behavior that when I use cairo it works fine
but when I use pango segmentation fault occurs.

Is it because of pango_cairo_font_map_get_default() or thread ?
but considering ev_job_render_run (EvJob *job) in libview/ev-jobs.c

    ev_document_fc_mutex_lock ()
    ...
    job_render->surface = ev_document_render (job->document, rc);
    ...
    ev_document_fc_mutex_unlock ()

Although pango is thread-safe since 1.32.6
when I tested in pango 1.30.0 / 1.32.5 / 1.34.1 / 1.35.0
segmentation fault alse occurred in all cases.

I don't know why.
Please advise me how to do.

To test libexample and evince-sample-backend please follow the below steps.

Step 1. Downloads the attachment and extract.

evince-sample-backend and libexample will be created.

Step 2. compile and install libexample

cd libexample
./autogen.sh
make
sudo make install
sudo ldconfig
cd ..

Step 3. compile and install evince-sample-backend

cd evince-sample-backend
./autogen.sh
make
sudo make install
sudo ldconfig

Step 4. open the any text file from the terminal with evince many times.

$ evince any.txt


My current environment:
debian wheezy
evince          3.4.0-3.1
libpango1.0-0   1.30.0-1
libcairo2       1.12.2-3

Attachment: projects.tar.gz
Description: GNU Zip compressed data



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