aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-02-09 13:25:45 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-09 13:25:45 -0800
commit0449bcfb2fa1dd33cb3a4c0c8b17960d17edf01a (patch)
tree8c9e8f7e7b02e5a337636a5f41e981ba4e363d59 /include
parent3cb954245cecf262d740a83913681b9fe4b41555 (diff)
add helper to create fancy underlines
Add a couple of utility functions to SkPaint that return the bounds of glyphs between a pair of lines. The common use case envisioned generates the edges of descenders between the top and bottom bounds of an underline to allow computing a stroke that skips those descenders. The implementation stores a linked list in each glyph containing the bounds of the lines parallel to the advance and the outermost intersections within those bounds. When the glyph cache is constructed, the glyph path is intersected with the bounds and the extreme min and max values within the bounds is added to an intercept. Share the text to path iter to construct the data. Make a half-hearted attempt to support vertical text; while the vertical implementation is complete; surrounding code (e.g. paint align) has short-comings with vertical. R=fmalita@chromium.org, reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1654883003 Review URL: https://codereview.chromium.org/1654883003
Diffstat (limited to 'include')
-rw-r--r--include/core/SkPaint.h60
1 files changed, 56 insertions, 4 deletions
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index a0def42f12..cd170bc94f 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -885,15 +885,67 @@ public:
SkRect bounds[] = NULL) const;
/** Return the path (outline) for the specified text.
- Note: just like SkCanvas::drawText, this will respect the Align setting
- in the paint.
- */
+ * Note: just like SkCanvas::drawText, this will respect the Align setting
+ * in the paint.
+ *
+ * @param text the text
+ * @param length number of bytes of text
+ * @param x The x-coordinate of the origin of the text.
+ * @param y The y-coordinate of the origin of the text.
+ * @param path The outline of the text.
+ */
void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
SkPath* path) const;
+ /** Return the path (outline) for the specified text.
+ * Note: just like SkCanvas::drawText, this will respect the Align setting
+ * in the paint.
+ *
+ * @param text the text
+ * @param length number of bytes of text
+ * @param pos array of positions, used to position each character
+ * @param path The outline of the text.
+ */
void getPosTextPath(const void* text, size_t length,
const SkPoint pos[], SkPath* path) const;
+ /** Return the number of intervals that intersect the intercept along the axis of the advance.
+ * The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in
+ * the string. The caller may pass nullptr for intervals to determine the size of the interval
+ * array, or may conservatively pre-allocate an array with length * 2 entries. The computed
+ * intervals are cached by glyph to improve performance for multiple calls.
+ * This permits constructing an underline that skips the descenders.
+ *
+ * @param text the text
+ * @param length number of bytes of text
+ * @param x The x-coordinate of the origin of the text.
+ * @param y The y-coordinate of the origin of the text.
+ * @param bounds The lower and upper line parallel to the advance.
+ * @param array If not null, the found intersections.
+ *
+ * @return The number of intersections, which may be zero.
+ */
+ int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
+ const SkScalar bounds[2], SkScalar* intervals) const;
+
+ /** Return the number of intervals that intersect the intercept along the axis of the advance.
+ * The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in
+ * string. The caller may pass nullptr for intervals to determine the size of the interval
+ * array, or may conservatively pre-allocate an array with length * 2 entries. The computed
+ * intervals are cached by glyph to improve performance for multiple calls.
+ * This permits constructing an underline that skips the descenders.
+ *
+ * @param text the text
+ * @param length number of bytes of text
+ * @param pos array of positions, used to position each character
+ * @param bounds The lower and upper line parallel to the advance.
+ * @param array If not null, the glyph bounds contained by the advance parallel lines.
+ *
+ * @return The number of intersections, which may be zero.
+ */
+ int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
+ const SkScalar bounds[2], SkScalar* intervals) const;
+
/**
* Return a rectangle that represents the union of the bounds of all
* of the glyphs, but each one positioned at (0,0). This may be conservatively large, and
@@ -1091,7 +1143,7 @@ private:
friend class GrTextUtils;
friend class GrGLPathRendering;
friend class SkScalerContext;
- friend class SkTextToPathIter;
+ friend class SkTextBaseIter;
friend class SkCanonicalizePaint;
};