Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 28, 2025

The createTextPath function in web_content_renderer.cpp was failing to correctly extract glyph paths from CJK (Chinese, Japanese, Korean) characters when processing mixed CJK/English text. This prevented CSS background-clip: text effects from working properly with multilingual content.

Problem

The original implementation used a single font for the entire text string and manually calculated glyph positions:

// Old approach - single font selection
sk_sp<SkTypeface> typeface = fontCollection->findTypefaces(...)[0];
SkFont font(typeface, fontSize);
font.textToGlyphs(textContent.c_str(), textContent.size(), ...);
// Manual positioning and glyph path extraction

This approach failed because:

  • No single font provides high-quality glyphs for both English and CJK scripts
  • Manual glyph positioning didn't account for complex script requirements
  • When the selected font lacked CJK glyphs, font.getPath() would fail and CJK characters were silently skipped

Solution

Replaced the single-font approach with Skia's paragraph visitor pattern, which leverages the paragraph system's proper font resolution:

// New approach - use paragraph's resolved fonts
paragraph->visit([&](int lineNumber, const Paragraph::VisitorInfo* info) {
  for (int i = 0; i < info->count; ++i) {
    SkPath glyphPath;
    if (info->font.getPath(info->glyphs[i], &glyphPath)) {
      // Uses the correct font for each glyph
      // Uses paragraph's calculated positions
    }
  }
});

Impact

This fix enables background-clip: text CSS effects to work correctly with:

  • Pure CJK text: "你好世界"
  • Mixed scripts: "Hello 你好 World 世界"
  • Complex multilingual content: "News 新闻 ニュース 뉴스 📰"

Example CSS that now works with CJK text:

.gradient-text {
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
}

The change is minimal (28 additions, 70 deletions) and leverages existing Skia infrastructure rather than maintaining custom text layout logic.

Fixes #150.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 28, 2025 15:27
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix: createTextPath cannot correctly retrieve CJK glyphs when mixing CJK and English text Fix createTextPath CJK glyph extraction for mixed CJK/English text Jul 28, 2025
Copilot AI requested a review from yorkie July 28, 2025 15:33
@yorkie yorkie marked this pull request as ready for review July 29, 2025 06:44
@yorkie yorkie merged commit 15c293b into main Jul 29, 2025
2 checks passed
@yorkie yorkie deleted the copilot/fix-150 branch July 29, 2025 06:58
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.

Fix: createTextPath cannot correctly retrieve CJK glyphs when mixing CJK and English text

2 participants