On Wed, Dec 7, 2016 at 5:49 PM, Lucio <lucio.d...@gmail.com> wrote:
> The first issue is one of documentation. It says in
> <https://godoc.org/golang.org/x/image/font> that:
>
> DrawBytes draws s at the dot and advances the dot's location.
>
> But it leaves the question of what exactly those bytes are supposed to
> represent.

The bytes are presumed to be UTF-8 text. (What else would it be?) In
any case, I sent out https://go-review.googlesource.com/34095


> but one wonders what the idea is of passing encoded runes as
> bytes instead of using more direct runes for the purpose.

A text editor widget might expose its text content as a []byte,
instead of a []rune, since in the latter representation, the
underlying array takes 4x the memory for ASCII text, a common case.


> how does one convert a single rune (which I happen to need "measured" in the
> code I'm working on) to a byte slice for the benefit of DrawBytes' (it's
> actually MeasureBytes, in my case)? Do I seriously need to find a
> utf8.RuneEncode function somewhere?

Yes, it's in the standard library:
https://golang.org/pkg/unicode/utf8/#EncodeRune

Or, if you're less concerned about unnecessary memory allocations and
only want a simple API, to draw a single rune r, use DrawString
instead of DrawBytes:

d.DrawString(string(r))


> The second issue is I'm sure even more due to a lack of understanding on my
> part. Using the "UbuntuMono-RI.ttf" file I sourced somewhere, I get a
> "panic: runtime error: index out of range" when executing (specifically for
> debugging) ``font.MeasureString(instance, "\u2502")'' where "\u2501" and
> lower seem to work OK.

Can you mail me (off-list) that ttf file?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to