Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1074)

Side by Side Diff: third_party/WebKit/LayoutTests/svg/text/resources/highlightGlyphs.js

Issue 1847763002: Only synthesize grapheme widths once for surrogate pair characters (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address reviewer comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Highlight glyphs from multiple text elements using SVG text queries.
2
3 var colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"];
4 function highlightGlyphs(textElements, highlightContainer) {
5 // Highlight each glyph with a semi-transparent rectangle and
6 // a number corresponding to the queried character index.
7 for (var elemNum = 0; elemNum < textElements.length; ++elemNum) {
8 var text = textElements[elemNum];
9 var charCount = text.getNumberOfChars();
10 for (var index = 0; index < charCount; ++index) {
11 var color = colors[index % colors.length];
12 highlightGlyph(text, index, color, highlightContainer);
13 }
14 }
15 }
16
17 function highlightGlyph(textElement, index, color, highlightContainer) {
18 var extent = textElement.getExtentOfChar(index);
19
20 // Highlight rect that we've selected using the extent information
21 var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
22 rect.setAttribute("x", extent.x);
23 rect.setAttribute("y", extent.y);
24 rect.setAttribute("width", extent.width);
25 rect.setAttribute("height", extent.height);
26 rect.setAttribute("fill-opacity", "0.5");
27 rect.setAttribute("fill", color);
28 highlightContainer.appendChild(rect);
29
30 // Output the start offset
31 var text = document.createElementNS("http://www.w3.org/2000/svg", "text");
32 text.setAttribute("x", extent.x + extent.width / 2);
33 text.setAttribute("y", extent.y + extent.height + 5);
34 text.setAttribute("text-anchor", "middle");
35 text.setAttribute("font-size", 8);
36 text.setAttribute("style", "-webkit-user-select: none; select: none;");
37 text.appendChild(document.createTextNode(index));
38 highlightContainer.appendChild(text);
39 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698