Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(components/): fix black bg on the right half of two-color characters may not be black 修正雙色字右半的黑背景不黑的問題 #101

Closed
wants to merge 2 commits into from

Conversation

IepIweidieng
Copy link
Contributor

@IepIweidieng IepIweidieng commented Dec 12, 2021

This issue was described in commit a75d550.
此問題已先爲 commit a75d550 所述。

This issue was caused by the HTML layout of two-color chars, e.g.:
此問題由雙色字的 HTML 排版導致,範例:

<span class="q15 b1">
    <span class="q15 b1b0 wpadding" data-text="" style="display: inline-block; width: 24px;"></span></span>

The "black" part of the background of the inner span is actually transparent, but the outer span has its own background (of the bg color of the left-half char), thus the "black" part of the inner span appeared to be not black.
內層 span 的背景的「黑色」部份實際上是透明的,但外層 span 有自己的背景(帶有左半雙色字的背景顏色),故內層 span 的「黑色」部份看起來並不黑。

To fix this issue, WordSegmentBuilder is specialized for two-color chars (as JavaScript class TwoColorWordBuilder) so as to instead generate such layout as:
爲了解決這個問題,WordSegmentBuilder 已對雙色字特例化(爲 JavaScript 類型 TwoColorWordBuilder)來把前述的排版改產生爲:

<span class="q15 b1b0 wpadding" data-text="" style="display: inline-block; width: 24px;"></span>
<span class="q15 b1"></span>

This no only avoids the unwanted background color introduced by the outer span but also eliminates the unnecessary outer span for a sole two-color char.
這不僅避免了外層 span 所導致的不想要的背景顏色,也消除了單獨出現的雙色字的不必要的外層 span。

Note that this requires a fix to TwoColorWord.js to make the un-nested span rendered expectedly. See the commit message for details.
注意這需要對 TwoColorWord.js 修正以讓未經多層套置的 span 按預期彩現。詳見 commit 訊息。

Test case

測試案例

Current behavior 目前行爲

image

Expected behavior (with this fix applied) 預期行爲(套用了此修正)

image

Sample text 範例文字

…rLead.fg === colorTail.fg`

This issue was caused by the following lines:
```js
    className={cx({
      [`q${colorLead.fg}`]: colorLead.fg === colorTail.fg,
// ...
      [`q${colorTail.fg}`]: colorLead.fg !== colorTail.fg,
// ...
```

When `colorLead.fg === colorTail.fg`, these lines were equivalent to:
```js
    className={cx({
      [`q${colorTail.fg}`]: true,
// ...
      [`q${colorTail.fg}`]: false,
// ...
```

Note that there were two lines containing the key `q${colorTail.fg}`,
where the second one overrode the first one,
thus made the q<fg> class missing from the HTML class list.

This was introduced by commit 38f10ba
("refactor(components/TwoColorWord): extract"),
which refactored this component with `classnames`
but did not success to address this error-prone detail.

This issue is fixed by always enabling the `q${colorTail.fg}` class.
…visual effects

This issue was described in commit a75d550
("Fix two-color character rendering bug when the right-half is black.").

However, another description is still given below.

This issue was caused by the HTML layout of two-color chars, e.g.:
```html
<span class="q15 b1">
    <span class="q15 b1b0 wpadding" data-text="A" style="display: inline-block; width: 24px;">
        A
    </span>
    M
</span>
```

The "black" part of the background of the inner span is actually transparent,
but the outer span has its own background (of the bg color of the left-half char),
thus the "black" part of the inner span appeared to be not black.

To fix this issue, WordSegmentBuilder is specialized for two-color chars
(as JavaScript class TwoColorWordBuilder)
so as to instead generate such layout as:
```html
<span class="q15 b1b0 wpadding" data-text="A" style="display: inline-block; width: 24px;">
    A
</span>
<span class="q15 b1">
    M
</span>
```

This no only avoids the unwanted background color introduced by the outer span
but also eliminates the unnecessary outer span for a sole two-color char.

Note that this requires the fix introduced in commit bafbe1e
("fix(components/TwoColorWord): fix missing q<fg> HTML class when `colorLead.fg === colorTail.fg`")
to make the un-nested span rendered expectedly.
@IepIweidieng IepIweidieng changed the title fix(components/): fix black bg on the right half of two-color characters may not be black fix(components/): fix black bg on the right half of two-color characters may not be black 修正雙色字右半的黑背景不黑的問題 Dec 9, 2022
@IepIweidieng
Copy link
Contributor Author

Integrated into #102.
已整合入 #102

@IepIweidieng IepIweidieng deleted the fix/r-half-bg0 branch January 15, 2023 15:23
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.

1 participant