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

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: 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 var textElements = document.querySelectorAll(".testTextRun");
fs 2016/03/31 09:01:41 This shadows the parameter (which is always this a
8 for (var elemNum = 0; elemNum < textElements.length; ++elemNum) {
9 var text = textElements[elemNum];
10 var charCount = text.getNumberOfChars();
11 for (var index = 0; index < charCount; ++index) {
12 var color = colors[index % colors.length];
13 highlightGlyph(text, index, color, highlightContainer);
14 }
15 }
16 }
17
18 function highlightGlyph(textElement, index, color, highlightContainer) {
19 var extent = textElement.getExtentOfChar(index);
20
21 // Highlight rect that we've selected using the extent information
22 var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
23 rect.setAttribute("x", extent.x);
24 rect.setAttribute("y", extent.y);
25 rect.setAttribute("width", extent.width);
26 rect.setAttribute("height", extent.height);
27 rect.setAttribute("fill-opacity", "0.5");
28 rect.setAttribute("fill", color);
29 highlightContainer.appendChild(rect);
30
31 // Output the start offset
32 var text = document.createElementNS("http://www.w3.org/2000/svg", "text");
33 text.setAttribute("x", extent.x + extent.width / 2);
34 text.setAttribute("y", extent.y + extent.height + 5);
35 text.setAttribute("text-anchor", "middle");
36 text.setAttribute("font-size", 8);
37 text.setAttribute("style", "-webkit-user-select: none; select: none;");
38 text.appendChild(document.createTextNode(index));
39 highlightContainer.appendChild(text);
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698