有色变音符号和unicode行为 [英] Colored diacritics and unicode behaviour

查看:57
本文介绍了有色变音符号和unicode行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了

这是怎么回事?我天真地猜到,字体渲染算法更喜欢像ōõöřǒ这样的预渲染字符,只要它们存在于字体中,而不是像 p̄m̃d̈ 这样的动态组合字符,则将其渲染为一个或追溯追溯到两个单独的项目,然后仅在第二种情况下触发变音符号着色.(请坦率地告诉我,当这种解释完全是胡说八道时.)此外,这意味着为变音符号着色的方法令人惊讶地实际上是在非标准情况下起作用的.谁能解释这种行为?并且是否也有办法对其他(完全蓝色)字母强制执行此操作?这是一种有趣"的问题,目前尚未与应用程序关联,但这可能是一个值得学习的案例.

我竖起了小提琴,因此您可以试用它.

解决方案

RandomGuy32提出的一种有效解决方案是

在基部之间插入组合字素连接器(U + 034F)字母和重音符号.这样,字体渲染器将不会尝试替换预先组合的字形,然后将颜色应用于每个字形字符.

我在小提琴(问题中提到的版本2)中进行了尝试.我将U + 034F直接放在每个基本字母后面,的确确实如此,正如RandomGuy32解释的那样.您在此处的代码块中看不到,因此我插入了一个注释以指示U + 034F的位置:

 o͏<!-U + 034F->< span>̄ 

但是,这将需要客户端或服务器端的渲染器处理带有变音符号的每个字母,然后将其分开并插入 span 和U + 034F.当您不想将文本加倍时,这可能是一个解决方案(如this question about coloring diacritics. The task was to color diacritics in another color than the base text, like in á presenting a in blue and ´ in red. I thought I could give it a try, separating letter and diacritic through unicode combining marks, and applying another color to the diacritics by putting a span around it, like this:

<p>
p<span>̄ </span>
o<span>̄ </span>
m<span>̃ </span>
o<span>̃ </span>
d<span>̈ </span>
o<span>̈ </span>
r<span>̌ </span>
o<span>̌ </span>
</p>

Now, having defined a simple CSS like this,

p { color:blue; }
span { color:red; }

I get the following, quite unforeseen but beautiful result:

What is happening here? I naively guessed that the font rendering algorithm prefers pre-rendered characters like ōõöřǒ, as long as they exist in the font, over dynamically combined ones like p̄m̃d̈, rendering it as one or two separate items retrospectively, which then triggers the diacritics coloring only in the second case. (Please tell me frankly when this interpretation is complete nonsense.) Further, this would mean that the approach for coloring diacritics surprisingly actually works under non-standard circumstances. Can anyone explain this behaviour? And would there be a way to enforce this for the other (completely blue) letters too? It is a kind of "fun" question not yet linked to an application right now, but it might be an interesting case to learn from.

I put up a fiddle so you can play around with it.

解决方案

One valid solution, as proposed by RandomGuy32, is

to insert the Combining Grapheme Joiner (U+034F) between the base letter and the accent. This way the font renderer won’t try to substitute the precomposed glyph and instead apply the colours to each character separately.

I tried this in the fiddle (version 2 of the one mentioned in my question). I put a U+034F directly after each base letter, and indeed this is working as RandomGuy32 explained. You do not see in the codeblock here, so I inserted a comment to indicate the position of U+034F:

o͏<!--U+034F--><span>̄

However, this would require a renderer on client or server side to process each letter with a diacritic, then separate it and insert both the span and U+034F. It might be a solution when you do not want to double your text (as proposed in a CSS based solutions on the page mentioned above).

这篇关于有色变音符号和unicode行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆