Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(754)

Issue 2208041: code review 2208041: freetype: make the point an argument to DrawString, not... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 2 months ago by nigeltao
Modified:
14 years, 2 months ago
Reviewers:
nigeltao_gnome, rog
CC:
r, golang-dev
Visibility:
Public.

Description

freetype: make the point an argument to DrawString, not part of the context state. Also rename DrawText to DrawString.

Patch Set 1 #

Patch Set 2 : code review 2208041: freetype: make the point an argument to DrawString, not... #

Patch Set 3 : code review 2208041: freetype: make the point an argument to DrawString, not... #

Unified diffs Side-by-side diffs Delta from patch set Stats (+14 lines, -22 lines) Patch
M example/freetype/main.go View 1 chunk +1 line, -2 lines 0 comments Download
M freetype/freetype.go View 1 2 4 chunks +13 lines, -20 lines 0 comments Download

Messages

Total messages: 8
nigeltao
Hello r (cc: golang-dev@googlegroups.com), I'd like you to review this change.
14 years, 2 months ago (2010-09-15 03:41:09 UTC) #1
r
LGTM
14 years, 2 months ago (2010-09-15 04:30:12 UTC) #2
nigeltao
*** Submitted as http://code.google.com/p/freetype-go/source/detail?r=9ae6c03d550c *** freetype: make the point an argument to DrawString, not part ...
14 years, 2 months ago (2010-09-15 04:35:39 UTC) #3
rog
at the risk of being boring, can i reiterate that i don't think the source ...
14 years, 2 months ago (2010-09-15 08:27:42 UTC) #4
nigeltao_gnome
On 15 September 2010 18:27, roger peppe <rogpeppe@gmail.com> wrote: > at the risk of being ...
14 years, 2 months ago (2010-09-17 02:30:41 UTC) #5
rog
On 17 September 2010 03:30, Nigel Tao <nigel.tao.gnome@gmail.com> wrote: > On 15 September 2010 18:27, ...
14 years, 2 months ago (2010-09-17 09:56:16 UTC) #6
nigeltao_gnome
On 17 September 2010 19:56, roger peppe <rogpeppe@gmail.com> wrote: > On 17 September 2010 03:30, ...
14 years, 2 months ago (2010-09-19 02:39:42 UTC) #7
rog
14 years, 2 months ago (2010-09-19 10:46:20 UTC) #8
On 19 September 2010 03:39, Nigel Tao <nigel.tao.gnome@gmail.com> wrote:
> On 17 September 2010 19:56, roger peppe <rogpeppe@gmail.com> wrote:
>> On 17 September 2010 03:30, Nigel Tao <nigel.tao.gnome@gmail.com> wrote:
>>> On 15 September 2010 18:27, roger peppe <rogpeppe@gmail.com> wrote:
>>>> at the risk of being boring, can i reiterate that i don't think
>>>> the source and destination rectangles and the clip rectangle
>>>> should be in the context either.
>>>
>>> On second thoughts, I think you're right. Maybe DrawString should be
>>> like draw.DrawMask, and take a dst, dr, src, sp, 'mask' and op. The
>>> difference between them is that DrawString uses a (string,
>>> raster.Point) to define a mask instead of an (image.Image,
>>> image.Point).
>>
>> that was the idea of my earlier suggestion for the API,
>> except i added in the clip rectangle, because it seems
>> difficult to simulate otherwise (without messing with Painters), and
>> it doesn't make
>> sense to pass dr, as the extent of the text is calculated by freetype.
>
> Maybe it isn't obvious (it makes sense to me, but I'm not a neutral
> witness), but dr acts as the clip.

yes, i realised that that's how you intended to use dr, but i'm not sure
it works well used like that.

in draw.DrawMask, dr acts not only as the clip rectangle, but
its min point also acts as the alignment point for the source
and mask images. i'm don't think it's working that way above,
which makes it subtly (and perhaps misleadingly) different from DrawMask,
even though it is defined with reference to DrawMask.

in your proposed arguments to DrawString above, i think
you are imagining that sp specifies the intersection of the first em square
and the baseline of the first character (i.e. where the text
will be drawn). but there's a problem: if this is aligned with dr.Min, then dr
cannot be the clip rectangle, because the text can drop below
the baseline. if it is not aligned with dr.Min, then where *is*
the source image going to be aligned? it's important to be
able to do the equivalent of both:

draw.DrawMask(dst, dr, src, sp, mask, sp, draw.Over)
and
draw.DrawMask(dst, dst, src, draw.ZP, mask, draw.ZP, draw.Over)

the first one shows a source image that remains still when the
points drawn at change; the second moves the source image along
with the drawn pixels.

> I guess I should polish up my toy text editor and publish it somewhere.

please do! polished or not...

>> how about this?
>>
>> // DrawText aligns p in dst with sp in src and draws the text s
>> // onto dst using src and operator op. No pixels are drawn outside clipr.
>> // It returns the next position for text to be drawn at.
>> func (c *Context) DrawString(dst draw.Image, p image.Point,
>>    src draw.Image, sp image.Point, s string, op draw.Op,
>>    clipr image.Rectangle) draw.Point
>
> At least one of those image.Points has to be a raster.Point if you
> want to be able to position text at sub-pixel resolution.
>
> http://www.antigrain.com/research/font_rasterization/index.html makes
> an argument for sub-pixel positioning.

i agree. and neither does the comment say where the text will actually
be drawn! (i intended p, not sp, by analogy with DrawMask, where the
second argument specifies the destination).

so we'd have

func (c *Context) DrawString(dst draw.Image, p raster.Point,
          src draw.Image, sp image.Point, s string, op draw.Op,
          clipr image.Rectangle)

however, one tricky issue: what does it mean to allign sp with p
when sp is pixel-based and p is sub-pixel-based?
if sp was a raster.Point, that would imply that we could do
sub-pixel operations in general, which we cannot.

perhaps we could say something like this:
// DrawText draws s at point p in dst using src and clipping
// to clipr. sp in src will be aligned to p in dst, rounded to
// the nearest whole pixel. The point p specifies the intersection
// of the text baseline with the left edge of the em square of
// the first character of the text.

PS another thought: if i wanted to draw one character in a string
in a different colour, would that break any kerning hints?
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b