scaling stroke

184 views
Skip to first unread message

Elijah Insua

unread,
May 20, 2013, 4:25:30 PM5/20/13
to skia-d...@googlegroups.com
Hello,

I've been working on building a html5 compatible CanvasContext2D with skia, and have run into an issue with strokes. Right now I'm using SkPaint to perform stroke operations, but to be compliant with html5 it seems the stroke needs to be scaled in other ways beyond transformMatrix.mapRadius(strokeWidth).  What are my options for accomplishing something like http://jsfiddle.net/MGndR/ in skia?

Thank you,
-- Elijah

Edison Nica

unread,
May 21, 2013, 10:02:29 AM5/21/13
to skia-d...@googlegroups.com
Hi Elijah,

Is it possible to send a png with the actual result you get, and the code you use?

If we have all the information, it is easier for anyone to take take a look, rather than guess what might be happening.

Thanks,
Edi


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Elijah Insua

unread,
May 21, 2013, 12:46:46 PM5/21/13
to skia-d...@googlegroups.com
Sure thing!


And the output I'm seeing is: Inline image 1
Thank you,
--Elijah


--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to skia-discuss...@googlegroups.com.
out.png

Edison Nica

unread,
May 21, 2013, 2:40:05 PM5/21/13
to skia-d...@googlegroups.com
If your project's licence is compatible with skia/webkit, you can just copy and paste the logic found in webkit/blink. I am not sure where that code is, and I heard it is pretty complicated to emulate HTML5 logic.

For this particular example, the trick is that rect coordinates use one matrix, while stoke (width and height) use another matrix. You could use SkPaint::getFillPath(...), which turns a stroked path into a filled path. Then this path can be scaled and filled as you wish. So instead of one drawPath, you will have 2 drawPath, the first one does only fill, the second one is a fill using stroke's color and getFillPath return path and a stoke's matrix.

ctx.beginPath();
ctx.scale(1.5, .5);              // this will scale only the coordinates of the rectangle
ctx.rect(50, 50, 75, 75);
ctx.scale(50, 25);              // this will scale only the stroke width and height
ctx.strokeStyle = "green";
ctx.stroke();

But there will be other problems when trying support HTML5 for other scenarios (transparency, antialiasing, ...)

Let us know if you need further assistance.
Edi
out.png

Elijah Insua

unread,
May 21, 2013, 4:02:25 PM5/21/13
to skia-d...@googlegroups.com
Edi,

I've been poking around in webkit/chromium's sources to figure out how to use skia actually.  Seems I'm fairly close to emulating a 2d context as of now, but there are probably more lurking issues as you've mentioned.

SkPaint::getFillPath(..) looks promising. I was wondering how SkStroke::strokePath(..) was intended to be used.

I'll give this a go, it appears to be exactly what I was looking for.

Thank you,
-- Elijah  
out.png

Mike Reed

unread,
May 21, 2013, 4:13:48 PM5/21/13
to skia-d...@googlegroups.com
afaik, canvas2d has a wacky notion of applying the CTM to each segment of the building-path "as they are added", rather than all at once during a draw. However, skia (and all sane packages) applies the CTM at draw-time. To accomodate canvas2d, the blink/webkit code does something like the following

Path::lineTo(x, y) {
    Matrix m = getCTM();
    Matrix inverse = m.invert();
    x', y' = inverse.map(x, y);
    path.lineTo(x', y');
}

... ugh.

out.png

Elijah Insua

unread,
May 21, 2013, 4:34:02 PM5/21/13
to skia-d...@googlegroups.com
Mike,

you are correct, and I second the "ugh" as an implementor at least.  I've been working around this by drawing the path with an identity matrix and applying the transform to points as they are added.  

Probably need to revisit that aspect of the code though, as it requires a SkCanvas::save() and SkCanvas::restore(). From what I've gleaned from reading code/ml threads these operations are relatively expensive.

-- Elijah
 
out.png

a.c...@weelya.com

unread,
May 21, 2013, 5:07:04 PM5/21/13
to skia-d...@googlegroups.com
Hey,

I also successfully implemented the whole 2Dcontext on top of skia.
I do something like this during a fill/stroke :

canvas->save(SkCanvas::kMatrix_SaveFlag);
canvas->resetMatrix();
canvas->drawPath(currentPath, currentPaint);
canvas->restore();

I don't think saving using "SkCanvas::kMatrix_SaveFlag" is that
expensive, is it?

And apply the current matrix at each point :

void Context2D::lineTo(double x, double y)
{
if (!currentPath) {
beginPath();
}

const SkMatrix &m = canvas->getTotalMatrix();
SkPoint pt = SkPoint::Make(SkDoubleToScalar(x),
SkDoubleToScalar(y));

SkMatrix::MapPtsProc proc = m.getMapPtsProc();

proc(m, &pt, &pt, 1);

if (!currentPath->countPoints()) {
currentPath->moveTo(pt);
} else {
currentPath->lineTo(pt);
}
}

Great to see some people facing sames issues ;-)

Anthony C.
>>>>> [5]
>>>>>
>>>>> And the output I'm seeing is: 
>>>>> Thank you,
>>>>> --Elijah
>>>>>
>>>>> On Tue, May 21, 2013 at 7:02 AM, Edison Nica <edi...@google.com>
>>>>> wrote:
>>>>>
>>>>>> Hi Elijah,
>>>>>>
>>>>>> Is it possible to send a png with the actual result you get, and
>>>>>> the code you use?
>>>>>>
>>>>>> If we have all the information, it is easier for anyone to take
>>>>>> take a look, rather than guess what might be happening.
>>>>>>
>>>>>> Thanks,
>>>>>> Edi
>>>>>>
>>>>>> On Mon, May 20, 2013 at 4:25 PM, Elijah Insua <tmp...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I've been working on building a html5 compatible
>>>>>>> CanvasContext2D with skia, and have run into an issue with
>>>>>>> strokes. Right now I'm using SkPaint to perform stroke
>>>>>>> operations, but to be compliant with html5 it seems the stroke
>>>>>>> needs to be scaled in other ways beyond
>>>>>>> transformMatrix.mapRadius(strokeWidth).  What are my options for
>>>>>>> accomplishing something like http://jsfiddle.net/MGndR/ [1] in
>>>>>>> skia?
>>>>>>>
>>>>>>> Thank you,
>>>>>>> -- Elijah
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the
>>>>>>> Google Groups "skia-discuss" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>> it, send an email to skia-discuss...@googlegroups.com.
>>>>>>>
>>>>>>> To post to this group, send email to
>>>>>>> skia-d...@googlegroups.com.
>>>>>>> Visit this group at
>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2].
>>>>>>> For more options, visit
>>>>>>> https://groups.google.com/groups/opt_out [3].
>>>>>>>  
>>>>>>>  
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to a topic
>>>>>> in the Google Groups "skia-discuss" group.
>>>>>> To unsubscribe from this topic, visit
>>>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>>>> [4].
>>>>>> To unsubscribe from this group and all its topics, send an email
>>>>>> to skia-discuss...@googlegroups.com.
>>>>>>
>>>>>> To post to this group, send email to
>>>>>> skia-d...@googlegroups.com.
>>>>>> Visit this group at
>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2].
>>>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>>>> [3].
>>>>>>  
>>>>>>  
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the
>>>>> Google Groups "skia-discuss" group.
>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>> send an email to skia-discuss...@googlegroups.com.
>>>>> To post to this group, send email to
>>>>> skia-d...@googlegroups.com.
>>>>> Visit this group at
>>>>> http://groups.google.com/group/skia-discuss?hl=en [2].
>>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>>> [3].
>>>>>  
>>>>>  
>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in
>>>> the Google Groups "skia-discuss" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>> [4].
>>>> To unsubscribe from this group and all its topics, send an email
>>>> to skia-discuss...@googlegroups.com.
>>>> To post to this group, send email to
>>>> skia-d...@googlegroups.com.
>>>> Visit this group at
>>>> http://groups.google.com/group/skia-discuss?hl=en [2].
>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>> [3].
>>>>  
>>>>  
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "skia-discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to skia-discuss...@googlegroups.com.
>>> To post to this group, send email to skia-d...@googlegroups.com.
>>> Visit this group at
>>> http://groups.google.com/group/skia-discuss?hl=en [2].
>>> For more options, visit https://groups.google.com/groups/opt_out
>>> [3].
>>>  
>>>  
>>
>> --
>> You received this message because you are subscribed to a topic in
>> the Google Groups "skia-discuss" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>> [4].
>> To unsubscribe from this group and all its topics, send an email to
>> skia-discuss...@googlegroups.com.
>> To post to this group, send email to skia-d...@googlegroups.com.
>> Visit this group at
>> http://groups.google.com/group/skia-discuss?hl=en [2].
>> For more options, visit https://groups.google.com/groups/opt_out
>> [3].
>>  
>>  
>
> --
> You received this message because you are subscribed to the Google
> Groups "skia-discuss" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to skia-discuss...@googlegroups.com.
> To post to this group, send email to skia-d...@googlegroups.com.
> Visit this group at
> http://groups.google.com/group/skia-discuss?hl=en [2].
> For more options, visit https://groups.google.com/groups/opt_out
> [3].
>
>
>
> Links:
> ------
> [1] http://jsfiddle.net/MGndR/
> [2] http://groups.google.com/group/skia-discuss?hl=en
> [3] https://groups.google.com/groups/opt_out
> [4]
> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
> [5]
> https://github.com/tmpvar/context2d/blob/master/src/context2d.cc#L925-L969

Elijah Insua

unread,
May 21, 2013, 6:33:01 PM5/21/13
to skia-d...@googlegroups.com
Anthony,

Good to know someone else out there is struggling/struggled with the same issues I am!

Is your implementation open source? I'd love to take a peek

Thanks,

--Elijah


To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.


To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2].
For more options, visit https://groups.google.com/groups/opt_out [3].
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en [4].

To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.


To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2].
For more options, visit https://groups.google.com/groups/opt_out [3].
 
 

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2].
For more options, visit https://groups.google.com/groups/opt_out [3].
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en [4].

To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2].
For more options, visit https://groups.google.com/groups/opt_out [3].
 
 

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2].
For more options, visit https://groups.google.com/groups/opt_out [3].
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en [4].

To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2].
For more options, visit https://groups.google.com/groups/opt_out [3].
 
 

 --
 You received this message because you are subscribed to the Google
Groups "skia-discuss" group.
 To unsubscribe from this group and stop receiving emails from it,

 To post to this group, send email to skia-d...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.

a.c...@weelya.com

unread,
May 22, 2013, 6:23:02 AM5/22/13
to skia-d...@googlegroups.com
Elijah,

Unfortunately, this is part of a bigger project which is not meant to
be opensource (yet) :-(

A.
>>>>>>> [5] [5]
>>>>>>>>> it, send an email to skia-discuss...@googlegroups.com.
>>>>>>>>>
>>>>>>>>> To post to this group, send email to
>>>>>>>>> skia-d...@googlegroups.com.
>>>>>>>>> Visit this group at
>>>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2].
>>>>>>>>> For more options, visit
>>>>>>>>> https://groups.google.com/groups/opt_out [3] [3].
>>>>>>>>>  
>>>>>>>>>  
>>>>>>>>
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to a
>>>>>>>> topic in the Google Groups "skia-discuss" group.
>>>>>>>> To unsubscribe from this topic, visit
>>>>>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>>>>>> [4] [4].
>>>>>>>>
>>>>>>>> To unsubscribe from this group and all its topics, send an
>>>>>>>> email to skia-discuss...@googlegroups.com.
>>>>>>>>
>>>>>>>> To post to this group, send email to
>>>>>>>> skia-d...@googlegroups.com.
>>>>>>>> Visit this group at
>>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2].
>>>>>>>> For more options, visit
>>>>>>>> https://groups.google.com/groups/opt_out [3] [3].
>>>>>>>>  
>>>>>>>>  
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the
>>>>>>> Google Groups "skia-discuss" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>> it, send an email to skia-discuss...@googlegroups.com.
>>>>>>> To post to this group, send email to
>>>>>>> skia-d...@googlegroups.com.
>>>>>>> Visit this group at
>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2].
>>>>>>> For more options, visit
>>>>>>> https://groups.google.com/groups/opt_out [3] [3].
>>>>>>>  
>>>>>>>  
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to a topic
>>>>>> in the Google Groups "skia-discuss" group.
>>>>>> To unsubscribe from this topic, visit
>>>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>>>> [4] [4].
>>>>>>
>>>>>> To unsubscribe from this group and all its topics, send an email
>>>>>> to skia-discuss...@googlegroups.com.
>>>>>> To post to this group, send email to
>>>>>> skia-d...@googlegroups.com.
>>>>>> Visit this group at
>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2].
>>>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>>>> [3] [3].
>>>>>>  
>>>>>>  
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the
>>>>> Google Groups "skia-discuss" group.
>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>> send an email to skia-discuss...@googlegroups.com.
>>>>> To post to this group, send email to
>>>>> skia-d...@googlegroups.com.
>>>>> Visit this group at
>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2].
>>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>>> [3] [3].
>>>>>  
>>>>>  
>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in
>>>> the Google Groups "skia-discuss" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>> [4] [4].
>>>>
>>>> To unsubscribe from this group and all its topics, send an email
>>>> to skia-discuss...@googlegroups.com.
>>>> To post to this group, send email to
>>>> skia-d...@googlegroups.com.
>>>> Visit this group at
>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2].
>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>> [3] [3].
>>>>  
>>>>  
>>>
>>>  --
>>>  You received this message because you are subscribed to the Google
>>> Groups "skia-discuss" group.
>>>  To unsubscribe from this group and stop receiving emails from it,
>>> send an email to skia-discuss...@googlegroups.com.
>>>  To post to this group, send email to
>>> skia-d...@googlegroups.com.
>>>  Visit this group at
>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2].
>>>  For more options, visit https://groups.google.com/groups/opt_out
>>> [3] [3].
>>>
>>> Links:
>>> ------
>>> [1] http://jsfiddle.net/MGndR/ [1]
>>> [2] http://groups.google.com/group/skia-discuss?hl=en [2]
>>> [3] https://groups.google.com/groups/opt_out [3]
>>> [4]
>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>> [4]
>>> [5]
>>> https://github.com/tmpvar/context2d/blob/master/src/context2d.cc#L925-L969
>>> [5]
>>
>> --
>> You received this message because you are subscribed to a topic in
>> the Google Groups "skia-discuss" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>> [4].
>> To unsubscribe from this group and all its topics, send an email to
>> skia-discuss...@googlegroups.com.
>> To post to this group, send email to skia-d...@googlegroups.com.
>> Visit this group at
>> http://groups.google.com/group/skia-discuss?hl=en [2].
>> For more options, visit https://groups.google.com/groups/opt_out
>> [3].
>
> --
> You received this message because you are subscribed to the Google
> Groups "skia-discuss" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to skia-discuss...@googlegroups.com.

Mike Reed

unread,
May 22, 2013, 8:12:16 AM5/22/13
to skia-d...@googlegroups.com
Agreed that save(matrix-flag) is pretty cheap.

However, this pattern will draw incorrectly if there is a shader on the paint (e.g. bitmap or gradient)

canvas.save
canvas.resetmatrix
canvas.drawpath(path, paint)
canvas.restore

This is because the shader (on the paint) looks at the CTM to know how to scale/rotate its colors, and that will be lost if the CTM is always identity.

Also, the strokeWidth on the paint will not get scaled correctly by the CTM if the paint's style is set to kStroke_Style.



To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.


To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2] [2].
For more options, visit https://groups.google.com/groups/opt_out [3] [3].
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en [4] [4].


To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.


To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2] [2].
For more options, visit https://groups.google.com/groups/opt_out [3] [3].
 
 

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2] [2].
For more options, visit https://groups.google.com/groups/opt_out [3] [3].
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en [4] [4].


To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2] [2].
For more options, visit https://groups.google.com/groups/opt_out [3] [3].
 
 

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2] [2].
For more options, visit https://groups.google.com/groups/opt_out [3] [3].
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en [4] [4].


To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2] [2].
For more options, visit https://groups.google.com/groups/opt_out [3] [3].
 
 

 --
 You received this message because you are subscribed to the Google
Groups "skia-discuss" group.
 To unsubscribe from this group and stop receiving emails from it,

 To post to this group, send email to skia-d...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en [4].
To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss?hl=en [2].
For more options, visit https://groups.google.com/groups/opt_out [3].

 --
 You received this message because you are subscribed to the Google
Groups "skia-discuss" group.
 To unsubscribe from this group and stop receiving emails from it,

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.

a.c...@weelya.com

unread,
May 22, 2013, 8:33:27 AM5/22/13
to skia-d...@googlegroups.com
ugh, you're right.

I guess that applying the invert-CTM on each point of the path is the
way to go then...
>>>>>>>>> [5] [5] [5]
>>>>>>>>>
>>>>>>>>> And the output I'm seeing is: 
>>>>>>>>>
>>>>>>>>> Thank you,
>>>>>>>>> --Elijah
>>>>>>>>>
>>>>>>>>> On Tue, May 21, 2013 at 7:02 AM, Edison Nica
>>>>>>>>> <edi...@google.com> wrote:
>>>>>>>>>
>>>>>>>>>> Hi Elijah,
>>>>>>>>>>
>>>>>>>>>> Is it possible to send a png with the actual result you get,
>>>>>>>>>> and the code you use?
>>>>>>>>>>
>>>>>>>>>> If we have all the information, it is easier for anyone to
>>>>>>>>>> take take a look, rather than guess what might be happening.
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Edi
>>>>>>>>>>
>>>>>>>>>> On Mon, May 20, 2013 at 4:25 PM, Elijah Insua
>>>>>>>>>> <tmp...@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Hello,
>>>>>>>>>>>
>>>>>>>>>>> I've been working on building a html5 compatible
>>>>>>>>>>> CanvasContext2D with skia, and have run into an issue with
>>>>>>>>>>> strokes. Right now I'm using SkPaint to perform stroke
>>>>>>>>>>> operations, but to be compliant with html5 it seems the
>>>>>>>>>>> stroke needs to be scaled in other ways beyond
>>>>>>>>>>> transformMatrix.mapRadius(strokeWidth).  What are my options
>>>>>>>>>>> for accomplishing something like http://jsfiddle.net/MGndR/
>>>>>>>>>>> [1] [1] [1] in skia?
>>>>>>>>>>>
>>>>>>>>>>> Thank you,
>>>>>>>>>>> -- Elijah
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>> Google Groups "skia-discuss" group.
>>>>>>>>>>> To unsubscribe from this group and stop receiving emails
>>>>>>>>>>> from it, send an email to
>>>>>>>>>>> skia-discuss...@googlegroups.com.
>>>>>>>>>>>
>>>>>>>>>>> To post to this group, send email to
>>>>>>>>>>> skia-d...@googlegroups.com.
>>>>>>>>>>> Visit this group at
>>>>>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2]
>>>>>>>>>>> [2].
>>>>>>>>>>> For more options, visit
>>>>>>>>>>> https://groups.google.com/groups/opt_out [3] [3] [3].
>>>>>>>>>>>  
>>>>>>>>>>>  
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> You received this message because you are subscribed to a
>>>>>>>>>> topic in the Google Groups "skia-discuss" group.
>>>>>>>>>> To unsubscribe from this topic, visit
>>>>>>>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>>>>>>>> [4] [4] [4].
>>>>>>>>>>
>>>>>>>>>> To unsubscribe from this group and all its topics, send an
>>>>>>>>>> email to skia-discuss...@googlegroups.com.
>>>>>>>>>>
>>>>>>>>>> To post to this group, send email to
>>>>>>>>>> skia-d...@googlegroups.com.
>>>>>>>>>> Visit this group at
>>>>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2] [2].
>>>>>>>>>> For more options, visit
>>>>>>>>>> https://groups.google.com/groups/opt_out [3] [3] [3].
>>>>>>>>>>  
>>>>>>>>>>  
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>> Google Groups "skia-discuss" group.
>>>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>>>> it, send an email to skia-discuss...@googlegroups.com.
>>>>>>>>> To post to this group, send email to
>>>>>>>>> skia-d...@googlegroups.com.
>>>>>>>>> Visit this group at
>>>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2] [2].
>>>>>>>>> For more options, visit
>>>>>>>>> https://groups.google.com/groups/opt_out [3] [3] [3].
>>>>>>>>>  
>>>>>>>>>  
>>>>>>>>
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to a
>>>>>>>> topic in the Google Groups "skia-discuss" group.
>>>>>>>> To unsubscribe from this topic, visit
>>>>>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>>>>>> [4] [4] [4].
>>>>>>>>
>>>>>>>> To unsubscribe from this group and all its topics, send an
>>>>>>>> email to skia-discuss...@googlegroups.com.
>>>>>>>> To post to this group, send email to
>>>>>>>> skia-d...@googlegroups.com.
>>>>>>>> Visit this group at
>>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2] [2].
>>>>>>>> For more options, visit
>>>>>>>> https://groups.google.com/groups/opt_out [3] [3] [3].
>>>>>>>>  
>>>>>>>>  
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the
>>>>>>> Google Groups "skia-discuss" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>> it, send an email to skia-discuss...@googlegroups.com.
>>>>>>> To post to this group, send email to
>>>>>>> skia-d...@googlegroups.com.
>>>>>>> Visit this group at
>>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2] [2].
>>>>>>> For more options, visit
>>>>>>> https://groups.google.com/groups/opt_out [3] [3] [3].
>>>>>>>  
>>>>>>>  
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to a topic
>>>>>> in the Google Groups "skia-discuss" group.
>>>>>> To unsubscribe from this topic, visit
>>>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>>>> [4] [4] [4].
>>>>>>
>>>>>> To unsubscribe from this group and all its topics, send an email
>>>>>> to skia-discuss...@googlegroups.com.
>>>>>> To post to this group, send email to
>>>>>> skia-d...@googlegroups.com.
>>>>>> Visit this group at
>>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2] [2].
>>>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>>>> [3] [3] [3].
>>>>>>  
>>>>>>  
>>>>>
>>>>>  --
>>>>>  You received this message because you are subscribed to the
>>>>> Google
>>>>> Groups "skia-discuss" group.
>>>>>  To unsubscribe from this group and stop receiving emails from
>>>>> it,
>>>>> send an email to skia-discuss...@googlegroups.com.
>>>>>  To post to this group, send email to
>>>>> skia-d...@googlegroups.com.
>>>>>  Visit this group at
>>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2] [2].
>>>>>  For more options, visit https://groups.google.com/groups/opt_out
>>>>> [3] [3] [3].
>>>>>
>>>>> Links:
>>>>> ------
>>>>> [1] http://jsfiddle.net/MGndR/ [1] [1]
>>>>> [2] http://groups.google.com/group/skia-discuss?hl=en [2] [2]
>>>>> [3] https://groups.google.com/groups/opt_out [3] [3]
>>>>> [4]
>>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>>> [4] [4]
>>>>> [5]
>>>>> https://github.com/tmpvar/context2d/blob/master/src/context2d.cc#L925-L969
>>>>> [5] [5]
>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in
>>>> the Google Groups "skia-discuss" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/skia-discuss/-IhQjlULa6k/unsubscribe?hl=en
>>>> [4] [4].
>>>> To unsubscribe from this group and all its topics, send an email
>>>> to skia-discuss...@googlegroups.com.
>>>> To post to this group, send email to
>>>> skia-d...@googlegroups.com.
>>>> Visit this group at
>>>> http://groups.google.com/group/skia-discuss?hl=en [2] [2].
>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>> [3] [3].
>>>
>>>  --
>>>  You received this message because you are subscribed to the Google
>>> Groups "skia-discuss" group.
>>>  To unsubscribe from this group and stop receiving emails from it,
>>> send an email to skia-discuss...@googlegroups.com.
>> You received this message because you are subscribed to the Google
>> Groups "skia-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to skia-discuss...@googlegroups.com.
>> To post to this group, send email to skia-d...@googlegroups.com.
>> Visit this group at
>> http://groups.google.com/group/skia-discuss?hl=en [2].
>> For more options, visit https://groups.google.com/groups/opt_out
>> [3].
>
> --
> You received this message because you are subscribed to the Google
> Groups "skia-discuss" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to skia-discuss...@googlegroups.com.

Elijah Insua

unread,
Jul 7, 2013, 9:46:46 PM7/7/13
to skia-d...@googlegroups.com
How'd that go for you?

Still not quite sure how this is supposed to work, even with the inverse-CTM method.

Lets say you do something like my original failure case, and run an inverse on the CTM when placing the rectangle.  Since there is no scale currently applied when placing the rectangle, it will still render incorrectly when attempting to scale the stroke.  It would appear that, after looking through blink's source, we need to maintain a stack of CTMs independent of skia's SkCanvas CTM. This way the rectangle would locate properly and the stroke would be applied using the latest transform. I believe this would also handle the case where you did some translate/rotate after .rect() prior to a .stroke().

Does this make sense, or am I totally off base here?

-- Elijah

Elijah Insua

unread,
Jul 10, 2013, 1:02:03 PM7/10/13
to skia-d...@googlegroups.com
Edi,


For this particular example, the trick is that rect coordinates use one matrix, while stoke (width and height) use another matrix. You could use SkPaint::getFillPath(...), which turns a stroked path into a filled path. Then this path can be scaled and filled as you wish. So instead of one drawPath, you will have 2 drawPath, the first one does only fill, the second one is a fill using stroke's color and getFillPath return path and a stoke's matrix.

This almost works, but it does not apply the scale prior to returning 2 closed paths.  Scaling these paths will result in scaling the overal geometry, not the stroke.

It would appear that blink only uses SkPaint::getFillPath in two places (Path::strokeContains and Path::strokeBoundingRect).  Following the code path for getFillPath looks like: SkPaint::getFillPath() -> SkStrokeRec::applyToPath() -> SkStroke::strokePath().  SkStroke::strokePath() appears to be pretty close to what im looking for, but will need to be re-written to include the current transform (scale) for the inner/outer path generation.  I'm ok with going down this road, but it feels wrong as the blink source doesn't really do any of this.  I'll keep digging around in the blink source; do you guys know of a blink dev who could help?
 
ctx.beginPath();
ctx.scale(1.5, .5);              // this will scale only the coordinates of the rectangle
ctx.rect(50, 50, 75, 75);
ctx.scale(50, 25);              // this will scale only the stroke width and height
ctx.strokeStyle = "green";
ctx.stroke();

Ok, since SkPaint does not have a CTM, what would be a reasonable way to go about this?

Thank you,
-- Elijah
 
Reply all
Reply to author
Forward
0 new messages