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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/svg/text/resources/highlightGlyphs.js
diff --git a/third_party/WebKit/LayoutTests/svg/text/resources/highlightGlyphs.js b/third_party/WebKit/LayoutTests/svg/text/resources/highlightGlyphs.js
new file mode 100644
index 0000000000000000000000000000000000000000..b8da2bb71df83f7ac4460e9fa4a49560dc08b16a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/svg/text/resources/highlightGlyphs.js
@@ -0,0 +1,40 @@
+// Highlight glyphs from multiple text elements using SVG text queries.
+
+var colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"];
+function highlightGlyphs(textElements, highlightContainer) {
+ // Highlight each glyph with a semi-transparent rectangle and
+ // a number corresponding to the queried character index.
+ var textElements = document.querySelectorAll(".testTextRun");
fs 2016/03/31 09:01:41 This shadows the parameter (which is always this a
+ for (var elemNum = 0; elemNum < textElements.length; ++elemNum) {
+ var text = textElements[elemNum];
+ var charCount = text.getNumberOfChars();
+ for (var index = 0; index < charCount; ++index) {
+ var color = colors[index % colors.length];
+ highlightGlyph(text, index, color, highlightContainer);
+ }
+ }
+}
+
+function highlightGlyph(textElement, index, color, highlightContainer) {
+ var extent = textElement.getExtentOfChar(index);
+
+ // Highlight rect that we've selected using the extent information
+ var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
+ rect.setAttribute("x", extent.x);
+ rect.setAttribute("y", extent.y);
+ rect.setAttribute("width", extent.width);
+ rect.setAttribute("height", extent.height);
+ rect.setAttribute("fill-opacity", "0.5");
+ rect.setAttribute("fill", color);
+ highlightContainer.appendChild(rect);
+
+ // Output the start offset
+ var text = document.createElementNS("http://www.w3.org/2000/svg", "text");
+ text.setAttribute("x", extent.x + extent.width / 2);
+ text.setAttribute("y", extent.y + extent.height + 5);
+ text.setAttribute("text-anchor", "middle");
+ text.setAttribute("font-size", 8);
+ text.setAttribute("style", "-webkit-user-select: none; select: none;");
+ text.appendChild(document.createTextNode(index));
+ highlightContainer.appendChild(text);
+}

Powered by Google App Engine
This is Rietveld 408576698