Skip to content

fix(render、pdf): respect color alpha channel#105

Merged
erweixin merged 4 commits into
mainfrom
fix-alphaColor
Jun 11, 2026
Merged

fix(render、pdf): respect color alpha channel#105
erweixin merged 4 commits into
mainfrom
fix-alphaColor

Conversation

@erweixin

@erweixin erweixin commented Jun 9, 2026

Copy link
Copy Markdown
Owner

close #103 #104

erweixin added 2 commits June 9, 2026 20:37
feat(renderer): refactor color painting logic into a separate function

test: add tests for rendering with transparent backgrounds and color alpha

test: update test cases to include new color formats
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploying ratex with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6bf1d6c
Status: ✅  Deploy successful!
Preview URL: https://87580c7b.ratex.pages.dev
Branch Preview URL: https://fix-alphacolor.ratex.pages.dev

View logs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbfbbb2d5e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// CID as 2-byte big-endian.
let cid_bytes = [(new_cid >> 8) as u8, (new_cid & 0xFF) as u8];

let alpha_applied = apply_non_stroking_alpha(content, color, alpha_states);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply alpha to raster emoji glyphs in PDFs

When a transparent \textcolor wraps a color emoji and collect_glyph_usage chooses an emoji raster, emit_glyph returns through the XObject branch before this new graphics-state application runs, so the PDF resource records the alpha but the emoji Do operation is emitted at full opacity. Wrap the emit_emoji_raster path with the same ExtGState save/restore so cases like \textcolor{#00000000}{🙂} do not render an opaque emoji.

Useful? React with 👍 / 👎.

@@ -561,13 +572,7 @@ fn render_glyph_with_font(
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply alpha to PNG raster emoji glyphs

This alpha-aware paint is only used after a glyph reaches render_glyph_with_font; on platforms with PNG emoji strikes, render_glyph/try_emoji_vector_then_bitmap return from try_blit_emoji_raster_fallback first, and that draw_pixmap uses default PixmapPaint opacity. As a result, transparent or semi-transparent \textcolor still produces opaque raster emoji in PNG output; pass the color alpha into the raster blit path as well.

Useful? React with 👍 / 👎.

@erweixin

erweixin commented Jun 9, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d08e0280c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/ratex-pdf/src/renderer.rs Outdated
}

if fill {
let alpha_applied = apply_non_stroking_alpha(content, color, alpha_states);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply alpha before constructing PDF paths

For any transparent DisplayItem::Path, this inserts q/gs after the m/l/c path construction operators and before the f/S painting operator. PDF path objects may only be completed by a painting operator (optionally after clipping), so strict renderers/preflight tools can treat these transparent filled or stroked paths as invalid/undefined; set the ExtGState before starting the path (as rects/lines do) or avoid wrapping the path mid-construction.

Useful? React with 👍 / 👎.

@erweixin

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@erweixin erweixin merged commit 30f7f2a into main Jun 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

render_to_png ignores alpha channel

1 participant