87
87
brasero_jacket_view_tag_begins (GtkTextIter *iter,
88
88
GtkTextAttributes *attributes)
90
91
PangoAttribute *attr;
91
92
GSList *open_attr = NULL;
94
index = gtk_text_iter_get_visible_line_index (iter);
93
95
attr = pango_attr_foreground_new (attributes->appearance.fg_color.red,
94
96
attributes->appearance.fg_color.green,
95
97
attributes->appearance.fg_color.blue);
96
attr->start_index = gtk_text_iter_get_visible_line_index (iter);
98
attr->start_index = index;
97
99
open_attr = g_slist_prepend (open_attr, attr);
99
101
attr = pango_attr_font_desc_new (attributes->font);
100
attr->start_index = gtk_text_iter_get_visible_line_index (iter);
102
attr->start_index = index;
101
103
open_attr = g_slist_prepend (open_attr, attr);
103
105
attr = pango_attr_underline_new (attributes->appearance.underline);
104
attr->start_index = gtk_text_iter_get_visible_line_index (iter);
106
attr->start_index = index;
105
107
open_attr = g_slist_prepend (open_attr, attr);
107
109
return open_attr;
163
165
gtk_text_attributes_unref (text_attr);
165
167
while (gtk_text_iter_forward_to_tag_toggle (&iter, NULL) &&
166
gtk_text_iter_get_line (&iter) == line_num &&
168
gtk_text_iter_compare (&iter, end) < 0 &&
167
169
!gtk_text_iter_is_end (&iter)) {
169
171
brasero_jacket_view_tag_ends (&iter, attributes, open_attr);
190
192
gtk_text_attributes_unref (text_attr);
193
/* Safer to do this in case one tag finishes on next line */
194
gtk_text_buffer_get_iter_at_line (buffer, &end, line_num);
195
gtk_text_iter_forward_to_line_end (&end);
197
195
/* go through all still opened attributes */
198
brasero_jacket_view_tag_ends (&end, attributes, open_attr);
196
brasero_jacket_view_tag_ends (end, attributes, open_attr);
199
197
g_slist_free (open_attr);
201
199
pango_layout_set_attributes (layout, attributes);
210
208
PangoLayout *layout,
211
209
gdouble resolution,
222
217
GtkTextBuffer *buffer;
218
GtkTextIter start, end;
219
PangoContext *pango_ctx;
223
220
BraseroJacketViewPrivate *priv;
221
cairo_font_options_t *font_options;
225
223
priv = BRASERO_JACKET_VIEW_PRIVATE (self);
225
cairo_set_source_rgb (ctx, 0.0, 0.0, 0.0);
227
/* This is vital to get the exact same layout when printing. By default
228
* this is off for printing and on for screen display */
229
font_options = cairo_font_options_create ();
230
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
231
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_ON);
232
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_SLIGHT);
233
cairo_set_font_options (ctx, font_options);
235
pango_ctx = pango_layout_get_context (layout);
236
pango_cairo_context_set_font_options (pango_ctx, font_options);
237
cairo_font_options_destroy (font_options);
239
pango_layout_set_width (layout, resolution * COVER_HEIGHT_SIDE_INCH * PANGO_SCALE);
242
y_left = y + COVER_HEIGHT_SIDE_INCH * resolution - 0.5;
244
x_right = x + COVER_WIDTH_BACK_INCH * resolution - 0.5;
227
247
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->sides));
228
line_max = gtk_text_buffer_get_line_count (buffer);
230
width = resolution * COVER_HEIGHT_SIDE_INCH;
232
y_left = y + COVER_HEIGHT_SIDE_INCH * resolution;
234
x_right = x + COVER_WIDTH_BACK_INCH * resolution;
237
for (line_num = 0; line_num < line_max; line_num ++) {
248
gtk_text_buffer_get_start_iter (buffer, &start);
251
while (!gtk_text_iter_is_end (&start)) {
239
253
PangoRectangle rect;
240
GtkTextIter start, end;
242
cairo_set_source_rgb (ctx, 0.0, 0.0, 0.0);
244
gtk_text_buffer_get_iter_at_line (buffer, &start, line_num);
245
gtk_text_buffer_get_iter_at_line (buffer, &end, line_num);
246
gtk_text_iter_forward_to_line_end (&end);
255
gtk_text_view_forward_display_line_end (GTK_TEXT_VIEW (priv->sides), &end);
248
257
text = brasero_jacket_buffer_get_text (BRASERO_JACKET_BUFFER (buffer), &start, &end, FALSE, FALSE);
249
258
if (text && text [0] != '\0' && text [0] != '\n') {
254
263
pango_layout_set_text (layout, " ", -1);
256
pango_layout_set_width (layout, width * PANGO_SCALE);
257
pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
258
brasero_jacket_view_set_line_attributes (GTK_TEXT_VIEW (priv->sides), layout, line_num);
260
pango_layout_get_pixel_extents (layout, NULL, &rect);
265
brasero_jacket_view_set_line_attributes (GTK_TEXT_VIEW (priv->sides), layout, &start, &end);
262
267
cairo_save (ctx);
278
283
cairo_restore (ctx);
285
pango_layout_get_pixel_extents (layout, NULL, &rect);
280
287
x_right -= rect.height;
281
288
x_left += rect.height;
290
gtk_text_view_forward_display_line (GTK_TEXT_VIEW (priv->sides), &end);
296
brasero_jacket_view_render_body (BraseroJacketView *self,
299
gdouble resolution_x,
300
gdouble resolution_y,
303
gboolean render_if_empty)
305
GtkTextBuffer *buffer;
306
GtkTextIter start, end;
307
PangoContext *pango_ctx;
308
BraseroJacketViewPrivate *priv;
309
cairo_font_options_t *font_options;
311
priv = BRASERO_JACKET_VIEW_PRIVATE (self);
313
/* This is vital to get the exact same layout when printing. By default
314
* this is off for printing and on for screen display */
315
font_options = cairo_font_options_create ();
316
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
317
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
318
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_SLIGHT);
319
cairo_set_font_options (ctx, font_options);
321
pango_ctx = pango_layout_get_context (layout);
322
pango_cairo_context_set_font_options (pango_ctx, font_options);
323
cairo_font_options_destroy (font_options);
325
/* This is necessary for the alignment of text */
326
if (priv->side == BRASERO_JACKET_BACK)
327
pango_layout_set_width (layout, (COVER_WIDTH_BACK_INCH - (COVER_WIDTH_SIDE_INCH + COVER_TEXT_MARGIN) * 2.0) * resolution_x * PANGO_SCALE);
329
pango_layout_set_width (layout, (COVER_WIDTH_FRONT_INCH - COVER_TEXT_MARGIN * 2.0) * resolution_x * PANGO_SCALE);
331
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->edit));
332
gtk_text_buffer_get_start_iter (buffer, &start);
335
while (!gtk_text_iter_is_end (&start)) {
339
gtk_text_view_forward_display_line_end (GTK_TEXT_VIEW (priv->edit), &end);
341
text = brasero_jacket_buffer_get_text (BRASERO_JACKET_BUFFER (buffer), &start, &end, FALSE, render_if_empty);
342
if (text && text [0] != '\0' && text [0] != '\n') {
343
pango_layout_set_text (layout, text, -1);
347
pango_layout_set_text (layout, " ", -1);
349
brasero_jacket_view_set_line_attributes (GTK_TEXT_VIEW (priv->edit), layout, &start, &end);
350
pango_cairo_update_layout (ctx, layout);
352
if (priv->side == BRASERO_JACKET_BACK)
354
x + (COVER_WIDTH_SIDE_INCH + COVER_TEXT_MARGIN) * resolution_x + 0.5,
355
y + COVER_TEXT_MARGIN * resolution_y);
358
x + COVER_TEXT_MARGIN * resolution_x + 0.5,
359
y + COVER_TEXT_MARGIN * resolution_y);
361
pango_cairo_show_layout (ctx, layout);
362
pango_layout_get_pixel_extents (layout, NULL, &rect);
365
gtk_text_view_forward_display_line (GTK_TEXT_VIEW (priv->edit), &end);
333
418
if (priv->image_style == BRASERO_JACKET_IMAGE_CENTER)
334
419
gdk_cairo_set_source_pixbuf (ctx,
336
x + (width - gdk_pixbuf_get_width (scaled))/ 2.0,
421
x + (width - gdk_pixbuf_get_width (scaled)) / 2.0,
337
422
y + (height - gdk_pixbuf_get_height (scaled)) / 2.0);
339
424
gdk_cairo_set_source_pixbuf (ctx, scaled, x, y);
351
436
if (priv->side == BRASERO_JACKET_BACK) {
437
gdouble line_x, line_y;
352
439
cairo_save (ctx);
354
441
/* Draw the rectangle */
355
cairo_set_antialias (ctx, CAIRO_ANTIALIAS_DEFAULT);
356
cairo_set_source_rgb (ctx, 0.5, 0.5, 0.5);
357
cairo_set_line_width (ctx, 0.5);
358
cairo_set_line_cap (ctx, CAIRO_LINE_CAP_ROUND);
361
x + COVER_WIDTH_SIDE_INCH * resolution_x,
364
x + COVER_WIDTH_SIDE_INCH * resolution_x,
365
y + (COVER_HEIGHT_SIDE_INCH * resolution_y));
368
x + (COVER_WIDTH_BACK_INCH - COVER_WIDTH_SIDE_INCH) * resolution_x,
371
x + (COVER_WIDTH_BACK_INCH - COVER_WIDTH_SIDE_INCH) * resolution_x,
372
y + (COVER_HEIGHT_SIDE_INCH * resolution_y));
442
cairo_set_source_rgb (ctx, 0.0, 0.0, 0.0);
443
cairo_set_line_width (ctx, 1.0);
445
line_y = y + (COVER_HEIGHT_SIDE_INCH * resolution_y) - 0.5;
447
line_x = (int) (x + (COVER_WIDTH_SIDE_INCH * resolution_x)) + 0.5;
455
line_x = (int) (x + ((COVER_WIDTH_BACK_INCH - COVER_WIDTH_SIDE_INCH) * resolution_x)) + 0.5;
374
463
cairo_stroke (ctx);
390
479
/* Draw the rectangle */
391
cairo_set_source_rgb (ctx, 0.5, 0.5, 0.5);
392
cairo_set_line_width (ctx, 0.5);
393
cairo_set_line_cap (ctx, CAIRO_LINE_CAP_ROUND);
480
cairo_set_source_rgb (ctx, 0.0, 0.0, 0.0);
481
cairo_set_line_width (ctx, 1.0);
395
483
cairo_rectangle (ctx,
400
488
cairo_stroke (ctx);
404
brasero_jacket_view_render_body (BraseroJacketView *self,
406
gdouble resolution_x,
407
gdouble resolution_y,
410
gboolean render_if_empty)
416
GtkTextBuffer *buffer;
417
BraseroJacketViewPrivate *priv;
419
priv = BRASERO_JACKET_VIEW_PRIVATE (self);
421
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->edit));
422
line_max = gtk_text_buffer_get_line_count (buffer);
424
if (priv->side == BRASERO_JACKET_BACK)
425
width = ((COVER_WIDTH_BACK_INCH - COVER_WIDTH_SIDE_INCH * 2) * resolution_x - COVER_TEXT_MARGIN * resolution_x * 2) * PANGO_SCALE;
427
width = (COVER_WIDTH_FRONT_INCH * resolution_x - COVER_TEXT_MARGIN * resolution_x * 2) * PANGO_SCALE;
429
for (line_num = 0; line_num < line_max; line_num ++) {
432
PangoContext *context;
433
GtkTextIter start, end;
435
cairo_set_source_rgb (ctx, 0.0, 0.0, 0.0);
436
layout = pango_cairo_create_layout (ctx);
438
context = pango_layout_get_context (layout);
439
pango_cairo_context_set_resolution (context, resolution_x);
441
gtk_text_buffer_get_iter_at_line (buffer, &start, line_num);
442
gtk_text_buffer_get_iter_at_line (buffer, &end, line_num);
443
gtk_text_iter_forward_to_line_end (&end);
445
text = brasero_jacket_buffer_get_text (BRASERO_JACKET_BUFFER (buffer), &start, &end, FALSE, render_if_empty);
446
if (text && text [0] != '\0' && text [0] != '\n') {
447
pango_layout_set_text (layout, text, -1);
451
pango_layout_set_text (layout, " ", -1);
453
pango_layout_set_width (layout, width);
454
pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
455
brasero_jacket_view_set_line_attributes (GTK_TEXT_VIEW (priv->edit), layout, line_num);
457
if (priv->side == BRASERO_JACKET_BACK)
459
x + COVER_WIDTH_SIDE_INCH * resolution_x + COVER_TEXT_MARGIN * resolution_x,
460
y + COVER_TEXT_MARGIN * resolution_y);
463
x + COVER_TEXT_MARGIN * resolution_x,
464
y + COVER_TEXT_MARGIN * resolution_y);
465
pango_cairo_show_layout (ctx, layout);
467
pango_layout_get_pixel_extents (layout, NULL, &rect);
470
g_object_unref (layout);
474
491
static GdkPixbuf *
475
492
brasero_jacket_view_scale_image (BraseroJacketView *self,
476
493
gdouble resolution_x,
523
540
if (priv->side == BRASERO_JACKET_BACK) {
524
rect.width = resolution_x * COVER_WIDTH_BACK_INCH;
525
rect.height = resolution_y * COVER_HEIGHT_BACK_INCH;
541
rect.width = (resolution_x * COVER_WIDTH_BACK_INCH) + 1.0;
542
rect.height = (resolution_y * COVER_HEIGHT_BACK_INCH) + 1.0;
528
rect.width = resolution_x * COVER_WIDTH_FRONT_INCH;
529
rect.height = resolution_y * COVER_HEIGHT_FRONT_INCH;
545
rect.width = (resolution_x * COVER_WIDTH_FRONT_INCH) + 1.0;
546
rect.height = (resolution_y * COVER_HEIGHT_FRONT_INCH) + 1.0;
532
549
/* Make sure we scale the image with the correct resolution */
566
584
return rect.height;
570
brasero_jacket_view_snapshot (BraseroJacketView *self)
572
BraseroJacketViewPrivate *priv;
573
cairo_surface_t *surface;
583
priv = BRASERO_JACKET_VIEW_PRIVATE (self);
585
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
586
if (!GTK_IS_WINDOW (toplevel))
589
resolution = gdk_screen_get_resolution (gtk_window_get_screen (GTK_WINDOW (toplevel)));
591
layout = gtk_widget_create_pango_layout (GTK_WIDGET (self), NULL);
593
if (priv->side == BRASERO_JACKET_BACK) {
594
width = resolution * COVER_WIDTH_BACK_INCH + 1;
595
height = resolution * COVER_HEIGHT_BACK_INCH + 1;
598
width = resolution * COVER_WIDTH_FRONT_INCH + 1;
599
height = resolution * COVER_HEIGHT_FRONT_INCH + 1;
602
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
605
ctx = cairo_create (surface);
607
/* make sure the image is scaled with the correct resolution */
608
if (priv->image_style == BRASERO_JACKET_IMAGE_STRETCH)
609
scaled = brasero_jacket_view_scale_image (self,
613
scaled = g_object_ref (priv->scaled);
615
gtk_widget_get_allocation (GTK_WIDGET (self), &area);
618
brasero_jacket_view_render (self,
629
/* Now let's render the text in main buffer */
630
brasero_jacket_view_render_body (self,
638
g_object_unref (layout);
644
588
brasero_jacket_view_cursor_position_changed_cb (GObject *buffer,
645
589
GParamSpec *spec,
702
641
GtkTextView *text_view = GTK_TEXT_VIEW (view);
703
642
GtkTextBuffer *buffer;
705
if (gtk_text_view_get_editable (text_view)) {
706
text_view->need_im_reset = TRUE;
707
gtk_im_context_focus_out (text_view->im_context);
710
644
buffer = gtk_text_view_get_buffer (text_view);
711
645
brasero_jacket_buffer_show_default_text (BRASERO_JACKET_BUFFER (buffer), TRUE);
713
647
g_signal_emit (self,
714
648
jacket_view_signals [TAGS_CHANGED],
1265
1199
return gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->sides));
1203
brasero_jacket_expose_textview (GtkWidget *widget,
1204
GtkWidget *textview,
1205
GdkEventExpose *event)
1207
GdkRectangle child_area;
1209
if (gtk_widget_intersect (textview, &event->area, &child_area)) {
1212
window = gtk_text_view_get_window (GTK_TEXT_VIEW (textview), GTK_TEXT_WINDOW_WIDGET);
1214
g_object_ref (window);
1215
gdk_window_invalidate_rect (window, &child_area, TRUE);
1216
gdk_window_process_updates (window, TRUE);
1217
g_object_unref (window);
1219
/* Reminder: the following would not work...
1220
* gtk_container_propagate_expose (GTK_CONTAINER (widget), textview, &child_event); */
1268
1224
static gboolean
1269
1225
brasero_jacket_view_expose (GtkWidget *widget,
1270
1226
GdkEventExpose *event)
1314
1269
cairo_move_to (ctx, 0., 0.);
1316
1271
cairo_set_antialias (ctx, CAIRO_ANTIALIAS_DEFAULT);
1317
cairo_set_source_rgb (ctx, 0.5, 0.5, 0.5);
1318
cairo_set_line_width (ctx, 0.5);
1272
cairo_set_source_rgb (ctx, 0.0, 0.0, 0.0);
1273
cairo_set_line_width (ctx, 1.0);
1319
1274
cairo_set_line_cap (ctx, CAIRO_LINE_CAP_ROUND);
1321
1276
gtk_widget_get_allocation (priv->sides, &sides_allocation);
1322
1277
cairo_rectangle (ctx,
1323
sides_allocation.x - 1,
1324
sides_allocation.y - 1,
1278
sides_allocation.x - 1 + 0.5,
1279
sides_allocation.y - 1 + 0.5,
1325
1280
sides_allocation.width + 2,
1326
1281
sides_allocation.height + 2);
1327
1282
cairo_stroke (ctx);
1329
gtk_container_propagate_expose (GTK_CONTAINER (widget),
1334
1285
x = (allocation.width - resolution * COVER_WIDTH_FRONT_INCH) / 2;
1411
1365
resolution = gdk_screen_get_resolution (gtk_window_get_screen (GTK_WINDOW (toplevel)));
1413
1367
if (priv->side == BRASERO_JACKET_FRONT) {
1414
request->width = COVER_WIDTH_FRONT_INCH * resolution + BRASERO_JACKET_VIEW_MARGIN * 2;
1415
request->height = COVER_HEIGHT_FRONT_INCH * resolution + BRASERO_JACKET_VIEW_MARGIN * 2;
1368
request->width = COVER_WIDTH_FRONT_INCH * resolution + BRASERO_JACKET_VIEW_MARGIN * 2.0;
1369
request->height = COVER_HEIGHT_FRONT_INCH * resolution + BRASERO_JACKET_VIEW_MARGIN * 2.0;
1417
1371
else if (priv->side == BRASERO_JACKET_BACK) {
1418
1372
request->width = COVER_WIDTH_BACK_INCH * resolution +
1419
BRASERO_JACKET_VIEW_MARGIN * 2;
1373
BRASERO_JACKET_VIEW_MARGIN * 2.0;
1420
1374
request->height = COVER_HEIGHT_BACK_INCH * resolution +
1421
1375
COVER_WIDTH_SIDE_INCH * resolution +
1422
BRASERO_JACKET_VIEW_MARGIN * 3;
1376
BRASERO_JACKET_VIEW_MARGIN * 3.0;
1467
1421
BRASERO_JACKET_VIEW_MARGIN +
1468
1422
COVER_TEXT_MARGIN * resolution;
1470
view_alloc.width = COVER_WIDTH_BACK_INCH * resolution -
1471
COVER_TEXT_MARGIN * resolution * 2 -
1472
COVER_WIDTH_SIDE_INCH * resolution * 2;
1473
view_alloc.height = COVER_HEIGHT_BACK_INCH * resolution -
1474
COVER_TEXT_MARGIN * resolution * 2;
1424
view_alloc.width = (COVER_WIDTH_BACK_INCH - (COVER_TEXT_MARGIN + COVER_WIDTH_SIDE_INCH) * 2.0) * resolution;
1425
view_alloc.height = (COVER_HEIGHT_BACK_INCH - COVER_TEXT_MARGIN * 2.0) * resolution;
1477
view_alloc.x = (allocation->width - COVER_WIDTH_FRONT_INCH * resolution) / 2 +
1428
view_alloc.x = (allocation->width - COVER_WIDTH_FRONT_INCH * resolution) / 2.0 +
1478
1429
COVER_TEXT_MARGIN * resolution;
1479
view_alloc.y = (allocation->height - resolution * COVER_HEIGHT_FRONT_INCH) / 2 +
1430
view_alloc.y = (allocation->height - resolution * COVER_HEIGHT_FRONT_INCH) / 2.0 +
1480
1431
COVER_TEXT_MARGIN * resolution;
1482
view_alloc.width = COVER_WIDTH_FRONT_INCH * resolution -
1483
COVER_TEXT_MARGIN * resolution * 2;
1484
view_alloc.height = COVER_HEIGHT_FRONT_INCH * resolution -
1485
COVER_TEXT_MARGIN * resolution * 2;
1433
view_alloc.width = (gdouble) (COVER_WIDTH_FRONT_INCH - COVER_TEXT_MARGIN * 2.0) * resolution;
1434
view_alloc.height = (gdouble) (COVER_HEIGHT_FRONT_INCH - COVER_TEXT_MARGIN * 2.0) * resolution;
1488
1437
brasero_jacket_view_update_edit_image (BRASERO_JACKET_VIEW (widget));