のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

do_output

239 void
240 do_output (PangoContext     *context,
241	   RenderCallback    render_cb,
242	   TransformCallback transform_cb,
243	   gpointer          cb_context,
244	   gpointer          cb_data,
245	   int              *width_out,
246	   int              *height_out)
247{
248  PangoLayout *layout;
249  PangoRectangle rect;
250  PangoMatrix matrix = PANGO_MATRIX_INIT;
251  PangoMatrix *orig_matrix;
252  gboolean supports_matrix;
253  int rotated_width, rotated_height;
254  int x = opt_margin_l;
255  int y = opt_margin_t;
256  int width, height;
257
258  width = 0;
259  height = 0;
260
261  orig_matrix = pango_matrix_copy (pango_context_get_matrix (context));
262  /* If the backend sets an all-zero matrix on the context,
263   * means that it doesn't support transformations.
264   */
265  supports_matrix = !orig_matrix ||
266		    (orig_matrix->xx != 0. || orig_matrix->xy != 0. ||
267		     orig_matrix->yx != 0. || orig_matrix->yy != 0. ||
268		     orig_matrix->x0 != 0. || orig_matrix->y0 != 0.);
269
270  set_transform (context, transform_cb, cb_context, cb_data, NULL);
271
272  pango_context_set_language (context,
273			      opt_language ? pango_language_from_string (opt_language)
274					   : pango_language_get_default ());
275  pango_context_set_base_dir (context,
276			      opt_rtl ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR);
277
278    if (opt_header)
279    {
280      char *options_string = get_options_string ();
281      pango_context_set_base_gravity (context, PANGO_GRAVITY_SOUTH);
282      layout = make_layout (context, options_string, 10);
283      pango_layout_get_extents (layout, NULL, &rect);
284
285      width = MAX (width, PANGO_PIXELS (rect.width));
286      height += PANGO_PIXELS (rect.height);
287
288      if (render_cb)
289	                 (*render_cb) (layout, x, y, cb_context, cb_data);
290
291      y += PANGO_PIXELS (rect.height);
292
293      g_object_unref (layout);
294      g_free (options_string);
295    }
296
297   if (opt_rotate != 0)
298    {
299      if (supports_matrix)
300	        pango_matrix_rotate (&matrix, opt_rotate);
301      else
302	        g_printerr ("The backend does not support rotated text\n");
303    }
304
305  pango_context_set_base_gravity (context, opt_gravity);
306  pango_context_set_gravity_hint (context, opt_gravity_hint);
307
308  layout = make_layout (context, text, -1);
309
310  set_transform (context, transform_cb, cb_context, cb_data, &matrix);
311
312  output_body (layout,
313	       NULL, NULL, NULL,
314	       &rotated_width, &rotated_height,
315	       supports_matrix);
316
317  rect.x = rect.y = 0;
318  rect.width = rotated_width;
319  rect.height = rotated_height;
320
321  pango_matrix_transform_pixel_rectangle (&matrix, &rect);
322
323  matrix.x0 = x - rect.x;
324  matrix.y0 = y - rect.y;
325
326  set_transform (context, transform_cb, cb_context, cb_data, &matrix);
327
328  if (render_cb)
329    output_body (layout,
330		 render_cb, cb_context, cb_data,
331		 &rotated_width, &rotated_height,
332		 supports_matrix);
333
334  width = MAX (width, rect.width);
335  height += rect.height;
336
337  width += opt_margin_l + opt_margin_r;
338  height += opt_margin_t + opt_margin_b;
339
340  if (width_out)
341    *width_out = width;
342  if (height_out)
343    *height_out = height;
344
345  pango_context_set_matrix (context, orig_matrix);
346  pango_matrix_free (orig_matrix);
347  g_object_unref (layout);
348}
349