ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Peter Rolf <indiego@gmx.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: kerning info (mkiv)
Date: Fri, 07 Jan 2011 14:48:32 +0100	[thread overview]
Message-ID: <4D2719B0.1090103@gmx.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]

Hi,

for a text background graphic I need the character box sizes of a given
string. I managed to collect the needed info (width, height, depth,
kerns), but there is still some flaw in the kerning part.

For example:

"VATo" is printed out (in the shell) as

V	12	11	0
*kerning	-85721.088
A	10	11	0
*kerning	-64487.424
T	10	11	0
*kerning	-64487.424
o	7	7	0

The character stands in the first column, followed by width, height and
depth (in pixel). The "*kerning" line shows the kerning value (in sp) of
the neighbouring character pair. No problem here.

But "A much longer Test graphic VATo"

A	12	11	0
 	5	0	0
m	13	7	0
*kerning	-21233.664
u	8	7	0
c	7	7	0
*kerning	-21233.664
h	8	11	0
 	5	0	0
l	4	11	0
o	7	7	0
n	9	7	0
g	8	7	3
e	7	7	0
r	6	7	0
 	5	0	0
T	11	11	0
e	7	7	0
s	6	7	0
t	6	10	0
 	5	0	0
g	8	7	3
r	6	7	0
a	8	7	0
p	9	7	3
h	8	11	0
i	4	10	0
c	7	7	0
 	5	0	0
V	12	11	0
A	12	11	0
T	11	11	0
o	7	7	0

sees no kerning for "VATo" (although the text is printed with the
correct kerning).

What am I missing? Example code is attached.

Peter

[-- Attachment #2: box.lua --]
[-- Type: text/x-lua, Size: 1355 bytes --]


-- http://lua-users.org/wiki/SimpleRound
local function round(num, idp)
    local mult = 10^(idp or 0)
    return math.floor(num * mult + 0.5) / mult
end

local function topixel(n)
    local dimenfactor = 1/49336
    return n*dimenfactor
end


function foo_box(text)
    local s = text

    local tfmdata = fonts.ids[font.current()]
    if tfmdata then
        local characters = tfmdata.characters

        local char = { }
        local lastchar
        local u,width,height,depth,kerns

        for i= 1,string.len(s) do
            u = utf.byte(string.sub(s,i,i))
            if not char[u] then
                width = characters[u].width or 0
                height = characters[u].height or 0
                depth = characters[u].depth or 0
                if lastchar then kerns = characters[lastchar].kerns
                    if kerns then
                        kern= kerns[u] or 0
                        if not(kern==0) then print("*kerning",kern) end
                    end
                else kern = 0
                end

                char[u] = {
                    w = round(topixel((width+kern))),
                    h = round(topixel(height)),
                    d = round(topixel(depth)) }
            end
            lastchar = u
            print(string.sub(s,i,i),char[u].w,char[u].h,char[u].d)
        end

    end
end


[-- Attachment #3: box.tex --]
[-- Type: text/plain, Size: 139 bytes --]

\registerctxluafile{box}{0.1}

\starttext

\ctxlua{foo_box("A much longer Test graphic VATo")}

\ctxlua{foo_box("VATo")}
\stoptext

[-- Attachment #4: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

             reply	other threads:[~2011-01-07 13:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-07 13:48 Peter Rolf [this message]
2011-01-07 14:13 ` Taco Hoekwater
2011-01-07 14:44   ` Peter Rolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D2719B0.1090103@gmx.net \
    --to=indiego@gmx.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).