Bug 18617

Summary: [CAIRO] SVG/Canvas fonts miss gradients/pattern support
Product: WebKit Reporter: Dirk Schulze <krit>
Component: SVGAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: alp
Priority: P2 Keywords: Cairo
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
dosplay of SVG-Text
none
Display SVG-text
none
Display SVG-text
none
Display texts in SVG and HTML
none
Painting of texts in SVG and HTML
none
Painting of texts in SVG and HTML
alp: review-
Fonts with Pattern/Gradient
none
Fonts with Pattern/Gradient
none
Fonts with Pattern/Gradient oliver: review+

Description Dirk Schulze 2008-04-19 00:50:01 PDT
The problem: The color of a Text in SVG is always black. It's related to WebCore/platform/graphics/cairo/FontCairo.cpp.

    cairo_set_source_rgba(cr, red, green, blue, alpha);

overwrites the color-set of SVG. But without the line, fonts in HTML get invisible. There should be something like:

    if (!svg) {}
Comment 1 Dirk Schulze 2008-04-20 12:15:14 PDT
It's a little bit more problematic. If you comment the line out (...source_rgb()) the text is rendered fine (gradients and colors). But if the text has a stroke. The complete text is filled with the settings of the stroke. 
Cg gives a setTextDrawingMode(cTextStroke) or setTextDrawingMode(cTextFill) in SVGPaintServer... back to GraphicsContext. 
Perhaps cairo should do the same?
Comment 2 Dirk Schulze 2008-04-24 23:16:33 PDT
Created attachment 20811 [details]
dosplay of SVG-Text

In Cairo SVG-text works with this changes. But texts on normal webpages are broken. Perhaps HTML-texts should do the same like SVG-texts. To hard-code the font-color isn't a good idea.
Comment 3 Dirk Schulze 2008-04-25 03:30:16 PDT
Created attachment 20815 [details]
Display SVG-text

SVG-Text is now displayed right and the most HTML-pages work now too. 
Some texts still don't get there color (like text in buttons or textfields). They are white. Stroke of HTML-text doesn't work like they should.
Comment 4 Dirk Schulze 2008-04-25 12:14:47 PDT
Created attachment 20821 [details]
Display SVG-text

The patch of above is the wrong file. Now the right one.
Comment 5 Dirk Schulze 2008-04-25 13:43:59 PDT
Created attachment 20823 [details]
Display texts in SVG and HTML

This patch fixes the problem with displaying texts in SVG and HTML. I had to use a workaround to get a full support.

I had to hard-code the fill-rule for SVG's to CAIRO_FILL_RULE_EVEN_ODD to differentiate between HTML- and SVG-texts. For HTML-text the font-color has to be hard-coded at present. If you don't do it (e.g. use of setPlatformFillColor(), see attachment above) not all HTML-objects are displayed right.
HTML makes only use of CAIRO_FILL_RULE_WINDING.

I couldn't find any optical differences in SVG between the two fill-rules.

This patch fixes bug-report: 18663, 15619 too.
Comment 6 Dirk Schulze 2008-04-26 04:29:52 PDT
Created attachment 20830 [details]
Painting of texts in SVG and HTML

Same changes like above:
SVG- and HTML-text are displayed well now, with a workaround. Added support for text-stroke (SVG needs it).

Plus text-shadow on stroked Texts in HTML/CSS.
Comment 7 Dirk Schulze 2008-04-26 22:58:19 PDT
Created attachment 20845 [details]
Painting of texts in SVG and HTML

The workaround only affects texts in SVG now. More information look 2 comments above.

This patch fixes bug-report: 18663, 15619 too.
Comment 8 Alp Toker 2008-04-28 13:22:34 PDT
Comment on attachment 20845 [details]
Painting of texts in SVG and HTML

I appreciate the push to get SVG fixed but we can't really take a patch that misuses fill rule as a flag to denote text drawing. We'll need to figure out how to do this properly -- we might need to fix the GraphicsContext abstraction if it's too closely tied to the assumption that the platform graphics library has separate brushes for text and graphics.
Comment 9 Dirk Schulze 2008-04-28 22:23:01 PDT
It should be possible to add displaysSVGtext() and setDiaplaysSVGtext() to GraphicsContext. You could differentiate between HTML- and SVG-text again but it would be a hack to.

Another idea was to use setPlatformFillColor(); and setPlatformStrokeColor();(Isn't used yet).

But if you try to give the fillColor to 'cairo_t* cr = m_data->cr;' with cairo_set_source_rgba(), not every text in HTML is affected by it (strange).
And there will be problems to include text-stroke of CSS into Cairo since the complete text uses the fillColor or the strokeColor (depending which Color was set at last).
Comment 10 Dirk Schulze 2008-11-12 23:36:56 PST
*** Bug 15619 has been marked as a duplicate of this bug. ***
Comment 11 Dirk Schulze 2008-11-12 23:44:11 PST
Solid colors will be fixed with https://bugs.webkit.org/show_bug.cgi?id=20699 (third part). I can't run LayoutTests, so I can't land it yet.

To fix patterns and gradients they have to be platformindependent first:
https://bugs.webkit.org/show_bug.cgi?id=21205
https://bugs.webkit.org/show_bug.cgi?id=20543
Comment 12 Dirk Schulze 2008-11-18 08:41:09 PST
Created attachment 25237 [details]
Fonts with Pattern/Gradient

Moved the fill and stroke code out of fillPath() and strokePath() to common methods for paths and texts.
Comment 13 Dirk Schulze 2008-11-18 08:47:09 PST
Created attachment 25238 [details]
Fonts with Pattern/Gradient

The same idea as the previous patch, but add own methods for text fill/stroke. The other patch could be a bit slower on filling paths (but not noticeable).

I would prefer the previous patch.
Comment 14 Dirk Schulze 2009-02-26 23:58:54 PST
Created attachment 28065 [details]
Fonts with Pattern/Gradient

Make use of the new calls fillGradient/strokeGradient and fillPattern/strokePattern in GraphicsContext to support patterns and gradient on Fonts in Cairo.
I also added support for globalAlpha on Fonts for Cairo.
Comment 15 Dirk Schulze 2009-02-27 00:01:50 PST
I forgot to mension that I commented the clipToImageBuffer on CanvasRenderingContext2D::drawTextInternal. Just CG needs this hack for filling and stroking texts with gradients. All other platforms have their own way to do it.
Comment 16 Oliver Hunt 2009-02-27 00:15:51 PST
Comment on attachment 28065 [details]
Fonts with Pattern/Gradient

r=me, the CG specific path makes me sad, oh well.
Comment 17 Dirk Schulze 2009-02-27 00:21:23 PST
landed in r41279.