<div dir="ltr">Hello.<br><br>I am developing evince backend for hwp document file.<br>I want to apply pango layout to evince hwp backend.<br><br>so, I tried to apply "Example 1. Using Pango with Cairo"<br>(<a href="https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html">https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html</a>)<br>
to SAMPLE evince backend and EXAMPLE library.<br><br>/* Example 1. Using Pango with Cairo */<br>/* <a href="https://developer.gnome.org/pango/1.34/pango-Cairo-Rendering.html">https://developer.gnome.org/pango/1.34/pango-Cairo-Rendering.html</a> */<br>
#include <math.h><br>#include <pango/pangocairo.h><br>static void<br>draw_text (cairo_t *cr)<br>{<br>#define RADIUS 150<br>#define N_WORDS 10<br>#define FONT "Sans Bold 27"<br>  PangoLayout *layout;<br>
  PangoFontDescription *desc;<br>  int i;<br>  /* Center coordinates on the middle of the region we are drawing<br>   */<br>  cairo_translate (cr, RADIUS, RADIUS);<br>  /* Create a PangoLayout, set the font and text */<br>
  layout = pango_cairo_create_layout (cr);<br>  pango_layout_set_text (layout, "Text", -1);<br>  desc = pango_font_description_from_string (FONT);<br>  pango_layout_set_font_description (layout, desc);<br>  pango_font_description_free (desc);<br>
  /* Draw the layout N_WORDS times in a circle */<br>  for (i = 0; i < N_WORDS; i++)<br>    {<br>      int width, height;<br>      double angle = (360. * i) / N_WORDS;<br>      double red;<br>      cairo_save (cr);<br>
      /* Gradient from red at angle == 60 to blue at angle == 240 */<br>      red   = (1 + cos ((angle - 60) * G_PI / 180.)) / 2;<br>      cairo_set_source_rgb (cr, red, 0, 1.0 - red);<br>      cairo_rotate (cr, angle * G_PI / 180.);<br>
      /* Inform Pango to re-layout the text with the new transformation */<br>      pango_cairo_update_layout (cr, layout);<br>      pango_layout_get_size (layout, &width, &height);<br>      cairo_move_to (cr, - ((double)width / PANGO_SCALE) / 2, - RADIUS);<br>
      pango_cairo_show_layout (cr, layout);<br>      cairo_restore (cr);<br>    }<br>  /* free the layout object */<br>  g_object_unref (layout);<br>}<br><br>gboolean example_page_render (ExamplePage *page, cairo_t *cr)<br>
{<br>    g_return_val_if_fail (EXAMPLE_IS_PAGE (page), FALSE);<br>    draw_text (cr);<br>    return TRUE;<br>}<br><br>then opened the sample text file from the terminal with evince<br>but segmentation fault occurred intermittently.<br>
<br>I cannot understand the behavior that when I use cairo it works fine<br>but when I use pango segmentation fault occurs.<br><br>Is it because of pango_cairo_font_map_get_default() or thread ?<br>but considering ev_job_render_run (EvJob *job) in libview/ev-jobs.c<br>
<br>    ev_document_fc_mutex_lock ()<br>    ...<br>    job_render->surface = ev_document_render (job->document, rc);<br>    ...<br>    ev_document_fc_mutex_unlock ()<br><br>Although pango is thread-safe since 1.32.6<br>
when I tested in pango 1.30.0 / 1.32.5 / 1.34.1 / 1.35.0<br>segmentation fault alse occurred in all cases.<br><br>I don't know why.<br>Please advise me how to do.<br><br>To test libexample and evince-sample-backend please follow the below steps.<br>
<br>Step 1. Downloads the attachment and extract.<br><br>evince-sample-backend and libexample will be created.<br><br>Step 2. compile and install libexample<br><br>cd libexample<br>./autogen.sh<br>make<br>sudo make install<br>
sudo ldconfig<br>cd ..<br><br>Step 3. compile and install evince-sample-backend<br><br>cd evince-sample-backend<br>./autogen.sh<br>make<br>sudo make install<br>sudo ldconfig<br><br>Step 4. open the any text file from the terminal with evince many times.<br>
<br>$ evince any.txt<br><br><br>My current environment:<br>debian wheezy<br>evince          3.4.0-3.1<br>libpango1.0-0   1.30.0-1<br>libcairo2       1.12.2-3<br></div>