有色变音符号和unicode行为

编程入门 行业动态 更新时间:2024-10-28 03:22:49
本文介绍了有色变音符号和unicode行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我偶然发现了

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

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

解决方案

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

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

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

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

但是,这将需要客户端或服务器端的渲染器处理带有变音符号的每个字母,然后将其分开并插入 span 和U + 034F.当您不想将文本加倍时,这可能是一个解决方案(如页面).

I just stumbled over 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行为

本文发布于:2023-10-26 23:00:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531598.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   unicode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!