[vector-draw] Add PDF fill opacity via inline ExtGState

The PDF draw context was dropping foreground alpha because
it had no resource dict for ExtGState.  Semi-transparent
fills (e.g. --rainbow) rendered fully opaque.

Add a per-flush ExtGState with /ca (fill opacity) when
alpha < 255.  The ExtGState entries are inlined in the
page's resource dict — no separate PDF objects needed.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad Esfahbod committed 2026-04-17 02:18:47 -06:00
1 parent 9d1ce8c942
commit e76163ebc8
2 files changed
+24 -1

No files matched your search

+8 -1
View File
@@ -868,7 +868,14 @@ hb_vector_draw_render_pdf (hb_vector_draw_t *draw)
out.append_num (ex + ew);
out.append_c (' ');
out.append_num (-ey);
out.append_str ("] /Contents 4 0 R >>\nendobj\n");
out.append_str ("] /Contents 4 0 R");
if (draw->pdf_extgstate_dict.length)
{
out.append_str (" /Resources << /ExtGState << ");
out.append_len (draw->pdf_extgstate_dict.arrayZ, draw->pdf_extgstate_dict.length);
out.append_str (">> >>");
}
out.append_str (" >>\nendobj\n");
/* Object 4: Content stream */
offsets[3] = out.length;
+16
View File
@@ -26,6 +26,8 @@ struct hb_vector_draw_t
hb_vector_buf_t defs;
hb_vector_buf_t body;
hb_vector_buf_t path;
hb_vector_buf_t pdf_extgstate_dict;
unsigned pdf_extgstate_count = 0;
void set_precision (unsigned p)
{
@@ -77,6 +79,20 @@ struct hb_vector_draw_t
void flush_path_pdf ()
{
unsigned a = hb_color_get_alpha (foreground);
if (a < 255)
{
unsigned gs_idx = pdf_extgstate_count++;
body.append_str ("/GS");
body.append_unsigned (gs_idx);
body.append_str (" gs\n");
pdf_extgstate_dict.append_str ("/GS");
pdf_extgstate_dict.append_unsigned (gs_idx);
pdf_extgstate_dict.append_str (" << /Type /ExtGState /ca ");
pdf_extgstate_dict.append_num (a / 255.f, 4);
pdf_extgstate_dict.append_str (" >> ");
}
body.append_num (hb_color_get_red (foreground) / 255.f, 4);
body.append_c (' ');
body.append_num (hb_color_get_green (foreground) / 255.f, 4);