ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "黄复雄 via ntg-context" <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: 黄复雄 <aahuaang@gmail.com>
Subject: Re: Is rendering furigana over horizontal or vertical japanese text doable in ConTeXt?
Date: Mon, 22 Aug 2022 13:21:13 +0800	[thread overview]
Message-ID: <CAHN0TNgN-QQRQstNh9_uOp1QhAEcRXJe3jR5ku9TWV3AEB_x2Q@mail.gmail.com> (raw)
In-Reply-To: <3e917e1d-f80f-a96c-e402-c62a2c26c8a6@freedom.nl>

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

Dear Hans.
Thank you very much for so many examples and guidance.

In fact, I have read one of the examples in the followingup.pdf,
and the https://github.com/Fusyong/vertical-typesetting module I made
is based on the example.

The examples all worked after I changed the font settings according to
my Win10 OS;
and surprisingly, the ruby module also worked with \setscript[hanzi]
 (they don't work together in the example Mr. Wolfgang provided).
The only problem is that the offsets of glyphs are a bit inaccurate,
which may be related to the font,
and I will look into it further.
The examples I have adjusted are attached,
and the output PDF of them is not attached for being too big to the
limit of 100 KB.
(Just now I received a reply from the mailing list system asking to
adjust a over-length email,
I mistakenly thought it was about the one to Mr. Wolfgang, so that one
was duplicated and submitted,
please deal with it.)

By the way, I've finished checking and adjusting type-imp-mscore.mkiv,
scrp-cjk.lua, and char-scr.lua so far,
but the changes are a bit much (or maybe you can say a bit reckless),
so I'm hesitant to get back to you in order to minimize your troubles.
And as mentioned partly in an earlier email, I've made 3 modules that
support Chinese
(about vertical-typesetting,  Jiazhu or inline cutting note and punctuation)
and I'd be happy to contribute them to the ConTeXt project repository
when they're ripe,
if that's in line with the project policy. Your comments and guidance
are very welcome.

Best regards,
                     Huang Fusyong(黄复雄)

Hans Hagen via ntg-context <ntg-context@ntg.nl> 于2022年8月22日周一 00:20写道:
>
> On 8/21/2022 12:10 PM, Wolfgang Schuster via ntg-context wrote:
> > 黄复雄 via ntg-context schrieb am 21.08.2022 um 10:24:
> >> Currently, the ruby module does not seem to support cjk fonts? I have
> >> a preliminary implementation of furigana(pinyin in Chinese) as:
> attached a variant (no pdf attached) using wolfgangs font definition
> plus some more
>
> -----------------------------------------------------------------
>                                            Hans Hagen | PRAGMA ADE
>                Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>         tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : https://contextgarden.net
> ___________________________________________________________________________________

[-- Attachment #2: test-directions-006.lmtx --]
[-- Type: application/octet-stream, Size: 5407 bytes --]

\dontcomplain

% in font-imp-scripts, line 145, comment a few lines
%
%                 orientate = function(character)
%                     local width  = character.width or 0
%                     local height = character.height or 0
%                     local depth  = character.depth or 0
% --                     character.width       = height + depth + rightshift + rightshift
%                     character.height      = width - downshift
%                     character.depth       = shift
% --                     character.xoffset     = height + rightshift
% --                     character.yoffset     = - downshift
% --                     character.orientation = orientation
%                 end

\setuplayout[middle]

\starttext

\startluacode
    local nuts           = nodes.nuts

    local nextglyph      = nuts.traversers.glyph

    local newhlist       = nuts.pool.hlist

    local getboth        = nuts.getboth
    local setboth        = nuts.setboth
    local setlink        = nuts.setlink
    local getlist        = nuts.getlist
    local setlist        = nuts.setlist
    local setwhd         = nuts.setwhd
    local getwhd         = nuts.getwhd
    local setorientation = nuts.setorientation

    local getbox         = nuts.getbox

    local xheights       = fonts.hashes.xheights

    local function is_vertical(c)
        return c >= 0x04E00 and c <= 0x09FFF
    end

    function document.manipulate_one(boxnumber)

        local box  = getbox(boxnumber)
        local list = getlist(box)
        local all  = { }

        for n, c, f in nextglyph, list do
            if is_vertical(c) then
                all[n] = f
            end
        end

        for n, f in next, all do
            local o = .2 * xheights[f]
            local prev, next = getboth(n)
            setboth(n)
            local l = newhlist(n)
            local w, h, d = getwhd(n)
            setlink(prev,l,next)
            setwhd(l,h+d+o,w,0)
            setorientation(l,0x003,o/2,-o/2,0,h,d-o)
            if n == list then
                setlist(box,l)
            end
        end

    end

\stopluacode

\startluacode
    function document.manipulate_two(boxnumber)

        local box = tex.getbox(boxnumber)
        local n   = box.list

        local function is_vertical(c)
            return c >= 0x04E00 and c <= 0x09FFF
        end

        while n do
            if n.id == node.id("glyph") and is_vertical(n.char) then
                local o = .2 * fonts.hashes.identifiers[n.font].parameters.xheight
                local prev, next = n.prev, n.next
                n.next, n.prev = nil, nil
                local l = nodes.new("hlist")
                l.list = n
                local w, h, d = n.width, n.height, n.depth
                if prev then
                    prev.next, l.prev = l, prev
                else
                    box.list = l
                end
                if next then
                    l.next, next.prev = next, l
                end
                l.width, l.height, l.depth  = h + d + o, w, 0
                l.orientation = 0x003
--              l.xoffset, l.yoffset = o/2, -o/2
              l.hoffset, l.doffset = h, d - o
                n = next
            else
                n = n.next
            end
        end

    end

\stopluacode

% % % % % % % % % %

\unexpanded\def\stripe#1{\hbox orientation 0 yoffset 3pt{\strut #1}}

\setuptolerance[verytolerant,stretch]

\definefont[NotoCJK][file:simsun.ttc*default @ 24pt] \setupinterlinespace[40pt]

% % % % % % % % % %

\setbox1000\hbox{\NotoCJK\startscript[hangul]\dorecurse{20}{通用规范汉字表 \stripe{test #1} }\stopscript}
\ctxlua{document.manipulate_one(1000)}
\ruledvbox orientation 1 to \textwidth \bgroup
    \hsize \textheight
    \unhbox1000
    \vfill
\egroup
\page

\setbox1000\hbox{\NotoCJK\startscript[hangul]\dorecurse{20}{通用规范汉字表 \stripe{test #1} }\stopscript}
\ctxlua{document.manipulate_two(1000)}
\ruledvbox orientation 1 to \textwidth \bgroup
    \hsize \textheight
    \unhbox1000
    \vfill
\egroup
\page

\setupinterlinespace[40pt]

\definefontfeature
    [vertical]
    [vertical={%
        orientation=3,%
        down=.1,%
        right=.1,%
        ranges={%
            cjkcompatibility,%
            cjkcompatibilityforms,%
            cjkcompatibilityideographs,%
            cjkcompatibilityideographssupplement,%
            cjkradicalssupplement,%
          % cjkstrokes,%
            cjksymbolsandpunctuation,%
            cjkunifiedideographs,%
            cjkunifiedideographsextensiona,%
            cjkunifiedideographsextensionb,%
            cjkunifiedideographsextensionc,%
            cjkunifiedideographsextensiond,%
            cjkunifiedideographsextensione,%
            cjkunifiedideographsextensionf,%
        }%
    }]

\definefont[NotoCJKvertical][file:simsun.ttc*default,vertical @ 24pt]

\showglyphs

\unexpanded\def\stripe#1{\hbox orientation 0 yoffset 3pt{\strut #1}}

\setbox1000\hbox{\NotoCJKvertical\startscript[hangul]\dorecurse{20}{通用规范汉字表 \stripe{test #1} }\stopscript}

\ruledvbox orientation 1 to \textwidth \bgroup
    \hsize \textheight
    \unhbox1000
    \vfill
\egroup

% \stopscript

\stoptext

[-- Attachment #3: test-directions-005.lmtx --]
[-- Type: application/octet-stream, Size: 6926 bytes --]

\noheaderandfooterlines

% in font-imp-scripts, line 145, comment a few lines
%
%                 orientate = function(character)
%                     local width  = character.width or 0
%                     local height = character.height or 0
%                     local depth  = character.depth or 0
% --                     character.width       = height + depth + rightshift + rightshift
%                     character.height      = width - downshift
%                     character.depth       = shift
% --                     character.xoffset     = height + rightshift
% --                     character.yoffset     = - downshift
% --                     character.orientation = orientation
%                 end

\dontcomplain
\showglyphs

\setuplayout[middle]

\starttext

\startluacode
    local nuts          = nodes.nuts

    local nextglyph     = nuts.traversers.glyph
    local nextnode      = nuts.traversers.node

    local newhlist      = nuts.pool.hlist
    local newglue       = nuts.pool.glue
    local newpenalty    = nuts.pool.penalty

    local getprev       = nuts.getprev
    local setnext       = nuts.setnext
    local getnext       = nuts.getnext
    local setprev       = nuts.setprev
    local getboth       = nuts.getboth
    local setboth       = nuts.setboth
    local setlink       = nuts.setlink
    local getlist       = nuts.getlist
    local setlist       = nuts.setlist
    local setwhd        = nuts.setwhd
    local getwhd        = nuts.getwhd
    local getid         = nuts.getid
    local getchar       = nuts.getchar

    local getbox        = nuts.getbox

    local getdimensions = nuts.dimensions

    local setorientation  = nuts.setorientation
    local getorientation  = nuts.getorientation

    local glyph_code    = nodes.nodecodes.glyph
    local kern_code     = nodes.nodecodes.kern

    function document.manipulate_one(boxnumber)

        local box  = getbox(1000)
        local list = getlist(b)
        local all  = { }

        for n, c, f in nextglyph, list do
            if c > 200 then
                all[n] = true
            end
        end

        local o = 4 * 65536

        for n, how in next, all do
            local prev, next = getboth(n)
            setboth(n)
            local l = newhlist(n)
            local w, h, d = getwhd(n)
            setlink(prev,l,next)
            if how then
                setwhd(l,h+d+o,w,0)
                setorientation(l,0x003,0,0,h,d-o)
            end
            if n == list then
                setlist(box,l)
            end
        end

    end

    local function flushrange(head,current,first,last)
        local prev = getprev(first)
        local next = getnext(last)
        local list = newhlist(first)
        setprev(first)
        setnext(last)
        local w, h, d = getdimensions(first)
        setwhd(list,h+d,w,0)
        setlink(prev,list,next)
        setorientation(list,0x001,0,0,h,d)
        if first == head then
            return list, list
        else
            return head, list
        end
    end

    local function flushchar(head,current)
        local next = getnext(current)
        local glue = newglue(n,655360)
        setlink(current,glue,next)
        return head, glue
    end

    function document.manipulate_two(boxnumber)

        local box     = getbox(1000)
        local head    = getlist(box)
        local first   = false
        local last    = false
        local current = head
        while current do
            local id = getid(current)
            if id == glyph_code then
                if getchar(current) < 200 then
                    if first then
                        last = current
                    else
                        first = current
                        last  = current
                    end
                else
                    if first then
                        head, current = flushrange(head,current,first,last)
                        first = false
                    end
                    head, current = flushchar(head,current)
                end
            elseif id == kern_code then
                if first then
                    last = current
                end
            elseif first then
                head, current = flushrange(head,current,first,last)
                first = false
            end
            current = getnext(current)
        end
        if first then
            head, current = flushrange(head,current,first,last)
        end
        setlist(box,head)
    end

\stopluacode

% % % % % % % % % %

\setuptolerance[verytolerant,stretch]

\definefont[NotoCJK][file:simsun.ttc*default @ 24pt] \setupinterlinespace[40pt]

\unexpanded\def\stripe#1{\hbox orientation 0 yoffset 3pt{\strut #1}}

\setbox1000\hbox{\NotoCJK\startscript[hanzi]\dorecurse{20}{通用规范汉字表 \stripe{test #1} }\stopscript}

\ctxlua{document.manipulate_one(1000)}

\ruledvbox orientation 1 to \textwidth \bgroup
    \hsize \textheight
    \unhbox1000
    \vfill
\egroup

\page

\setbox1000\hbox{\NotoCJK\startscript[hanzi]\dorecurse{20}{通用规\ruby{范}{x}汉字表 \stripe{test #1} }\stopscript}

\ctxlua{document.manipulate_one(1000)}

\ruledvbox orientation 1 to \textwidth \bgroup
    \hsize \textheight
    \unhbox1000
    \vfill
\egroup

\page

\setupinterlinespace[40pt]

\definefontfeature
    [vertical]
    [vertical={%
        orientation=3,%
        down=0.1,%
        right=.1,%
        ranges={%
            cjkcompatibility,%
            cjkcompatibilityforms,%
            cjkcompatibilityideographs,%
            cjkcompatibilityideographssupplement,%
            cjkradicalssupplement,%
          % cjkstrokes,%
            cjksymbolsandpunctuation,%
            cjkunifiedideographs,%
            cjkunifiedideographsextensiona,%
            cjkunifiedideographsextensionb,%
            cjkunifiedideographsextensionc,%
            cjkunifiedideographsextensiond,%
            cjkunifiedideographsextensione,%
            cjkunifiedideographsextensionf,%
        }%
    }]

\definefont[NotoCJKvertical][file:simsun.ttc*default,vertical @ 24pt]

\showglyphs

\unexpanded\def\stripe#1{\hbox orientation 0 yoffset 3pt{\strut #1}}

\setbox1000\hbox{\NotoCJKvertical\startscript[hanzi]\dorecurse{20}{通用规范汉字表 \stripe{test #1} }\stopscript}

\ruledvbox orientation 1 to \textwidth \bgroup
    \hsize \textheight
    \unhbox1000
    \vfill
\egroup

\page

\setbox1000\hbox{\NotoCJKvertical\startscript[hanzi]\dorecurse{20}{通用规\ruby{范}{x}汉字表 \stripe{test #1} }\stopscript}

\ruledvbox orientation 1 to \textwidth \bgroup
    \hsize \textheight
    \unhbox1000
    \vfill
\egroup

% \stopscript

\stoptext

[-- Attachment #4: test-directions-008.lmtx --]
[-- Type: application/octet-stream, Size: 3363 bytes --]

% in font-imp-scripts, line 145, comment a few lines
%
%                 orientate = function(character)
%                     local width  = character.width or 0
%                     local height = character.height or 0
%                     local depth  = character.depth or 0
% --                     character.width       = height + depth + rightshift + rightshift
%                     character.height      = width - downshift
%                     character.depth       = shift
% --                     character.xoffset     = height + rightshift
% --                     character.yoffset     = - downshift
% --                     character.orientation = orientation
%                 end

\definefontfeature
    [vertical]
    [vertical={%
        orientation=3,%
        down=.1,%
        right=.1,%
        ranges={%
            cjkcompatibility,%
            cjkcompatibilityforms,%
            cjkcompatibilityideographs,%
            cjkcompatibilityideographssupplement,%
            cjkradicalssupplement,%
          % cjkstrokes,%
            cjksymbolsandpunctuation,%
            cjkunifiedideographs,%
            cjkunifiedideographsextensiona,%
            cjkunifiedideographsextensionb,%
            cjkunifiedideographsextensionc,%
            cjkunifiedideographsextensiond,%
            cjkunifiedideographsextensione,%
            cjkunifiedideographsextensionf,%
        }%
    }]

% \definefont[NotoCJKvertical]    [file:simsun.ttc*default,vertical @ 24pt]
% \definefont[NotoCJKverticalBold][file:simhei.ttf*default,vertical @ 48pt]

% \definefallbackfamily [documentfont] [rm] [Noto Serif CJK SC]     [preset=range:chinese,features={default,vertical}]
% \definefallbackfamily [documentfont] [ss] [Noto Sans CJK SC]      [preset=range:chinese,features={default,vertical}]
% \definefallbackfamily [documentfont] [tt] [Noto Sans Mono CJK SC] [preset=range:chinese,features={default,vertical}]

% \definefontfamily [documentfont] [rm] [Noto Serif]
% \definefontfamily [documentfont] [ss] [Noto Sans]
% \definefontfamily [documentfont] [tt] [Noto Sans Mono]

% \setupbodyfont [NotoCJKvertical,24pt]

\definefont[NotoCJKvertical]    [file:simsun.ttc*default,vertical @ 24pt]
% \usetypescriptfile[mscore]
\setupbodyfont [NotoCJKvertical,20pt]
% \usebodyfont   [NotoCJKvertical,20pt]

\setuppapersize
 [A4,landscape,rotated,270]
 [A4,portrait]

\setuplayout[middle]

\showframe

\setuphead
  [chapter]
  [numbercolor=darkred,
   conversion=chinesenumerals]

\setuptolerance
  [verytolerant,stretch]

\setupinterlinespace
  [40pt]

\setuplayout
  [color=darkblue]

\setuppagenumbering
  [location=footer]

\defineconversionset
  [pagenumber]
  []
  [chinesenumerals]

\protected\def\stripe#1{\hbox orientation 0 yoffset 3pt{\strut #1}}

\setscript[hanzi]

\showglyphs

\starttext

\NotoCJKvertical

% \startscript[hangul]

    \chapter{通用规}

    \placefigure
      [left,none]
      {汉字表}
      {\framed
         [width=4cm,
          height=2\lineheight,
          frame=off,
          backgroundcolor=darkgreen,
          foregroundcolor=white,
          background=color]
         {汉字表}}

    \dorecurse{40}{%
        通用规\ruby{范}{x}汉字表 \stripe{test #1}
    }

% \stopscript

\stoptext

[-- Attachment #5: Type: text/plain, Size: 496 bytes --]

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

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2022-08-22  5:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 11:02 amano.kenji via ntg-context
2022-08-15 11:43 ` Taco Hoekwater via ntg-context
2022-08-15 12:00   ` amano.kenji via ntg-context
2022-08-15 15:39     ` Wolfgang Schuster via ntg-context
2022-08-16 11:33       ` amano.kenji via ntg-context
2022-08-16 15:05         ` Wolfgang Schuster via ntg-context
2022-08-21  8:24         ` 黄复雄 via ntg-context
2022-08-21 10:00           ` Hans Hagen via ntg-context
2022-08-21 10:10           ` Wolfgang Schuster via ntg-context
2022-08-21 16:19             ` Hans Hagen via ntg-context
2022-08-22  5:21               ` 黄复雄 via ntg-context [this message]
2022-08-22  7:16                 ` Hans Hagen via ntg-context
2022-09-03 10:44                   ` 黄复雄 via ntg-context
2022-08-22  2:09             ` 黄复雄 via ntg-context
2022-08-22  4:52             ` 黄复雄 via ntg-context

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=CAHN0TNgN-QQRQstNh9_uOp1QhAEcRXJe3jR5ku9TWV3AEB_x2Q@mail.gmail.com \
    --to=ntg-context@ntg.nl \
    --cc=aahuaang@gmail.com \
    /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).