ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: 黄复雄 <aahuaang@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Re: Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
Date: Thu, 3 Oct 2024 07:45:08 +0800	[thread overview]
Message-ID: <CAHN0TNiFZGeU9t1GdY1Cofxndr71hU0CWphmjG5xOBAcWsQG8w@mail.gmail.com> (raw)
In-Reply-To: <ed971c53c02181ba590c3af504ae6ef8544fc1e4@hongfeng.ch>

I use \usetypescriptfile[mscore], which means using the font
configuration that comes with ConTeXt,
which is suitable for Windows systems. For details, see the
installation file type-imp-mscore.mkiv.
If you set the body font, both OpenType and TrueType are OK.

On Thu, Oct 3, 2024 at 6:42 AM <hf@hongfeng.ch> wrote:
>
> I'm curious what Chinese font(s) you are using with ConTeXt?  Are they OpenType font,
> or TrueType?
>
>
>
> October 2, 2024 at 12:56 PM, "黄复雄" <aahuaang@gmail.com> wrote:
>
> > This is a preliminary solution for inserting spaces between Chinese
> >
> > characters and non-Chinese characters
> >
> > ```ConTeXt
> >
> > \mainlanguage[cn]
> >
> > \language[cn]
> >
> > \setscript[hanzi]
> >
> > \usetypescriptfile[mscore]
> >
> > \usebodyfont [mschinese,12pt]
> >
> > \showglyphs
> >
> > \startluacode
> >
> > Thirddata = Thirddata or {}
> >
> > local glyph_id = nodes.nodecodes.glyph --node.id("glyph")
> >
> > local node_insertbefore = node.insertbefore
> >
> > local node_insertafter = node.insertafter
> >
> > local node_new = node.new
> >
> > local tex_sp = tex.sp
> >
> > local function ischinesechar(c)
> >
> > -- for more ranges:
> >
> > -- https://wiki.contextgarden.net/List_of_Unicode_blocks
> >
> > return (c >= 0x04E00 and c <= 0x09FFF)
> >
> > or (c >= 0x03400 and c <= 0x04DBF)
> >
> > or (c >= 0x20000 and c <= 0x2A6DF)
> >
> > end
> >
> > function Thirddata.processmystuff(head)
> >
> > local n = head
> >
> > while n do
> >
> > if n.id == glyph_id and ischinesechar(n.char) then
> >
> > local n_prev = n.prev
> >
> > if n_prev
> >
> > and n_prev.id == glyph_id
> >
> > and not ischinesechar(n_prev.char)
> >
> > then
> >
> > local glue = node_new("glue")
> >
> > glue.width = tex_sp("0.25em")
> >
> > glue.stretch = tex_sp("0.25em")
> >
> > print("insert space before:", utf8.char(n.char))
> >
> > head, glue = node_insertbefore(head, n, glue)
> >
> > end
> >
> > local n_next = n.next
> >
> > if n_next
> >
> > and n_next.id == glyph_id
> >
> > and not ischinesechar(n_next.char)
> >
> > then
> >
> > local glue = node_new("glue")
> >
> > glue.width = tex_sp("0.25em")
> >
> > glue.stretch = tex_sp("0.25em")
> >
> > print("insert space after:", utf8.char(n.char))
> >
> > head, glue = node_insertafter(head, n, glue)
> >
> > n = glue.next
> >
> > end
> >
> > end
> >
> > n = n.next
> >
> > end
> >
> > return head, done
> >
> > end
> >
> > nodes.tasks.appendaction("processors", "after", "Thirddata.processmystuff")
> >
> > \stopluacode
> >
> > \starttext
> >
> > 今天出去买菜花了5000元。
> >
> > 新MacBook Pro有15\%的CPU性能提升。
> >
> > \stoptext
> >
> > ```
> >
> > On Tue, Oct 1, 2024 at 2:07 PM <ai2472206007@yeah.net> wrote:
> >
> >> hi,
> >>
> >> Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
> >>
> >> I noticed that there is a tracker that tracks character types and annotates them.
> >>
> >> But I don't know much about lua and the underlying tex.
> >>
> >> Any suggestions would be greatly appreciated.
> >>
> >> For example, glue is automatically added between Chinese characters and English or numbers.
> >>
> >> input: 今天出去买菜花了5000元。
> >>
> >> will get: 今天出去买菜花了 5000 元。
> >>
> >> ----------------------------------
> >>
> >> input: 新MacBook Pro有15%的CPU性能提升。
> >>
> >> will get: 新 MacBook Pro 有 15% 的 CPU 性能提升。
> >>
> >> Muyik
> >>
> >> ___________________________________________________________________________________
> >>
> >> If your question is of interest to others as well, please add an entry to the Wiki!
> >>
> >> maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> >>
> >> webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> >>
> >> archive : https://github.com/contextgarden/context
> >>
> >> wiki : https://wiki.contextgarden.net
> >>
> >> ___________________________________________________________________________________
> >
> > ___________________________________________________________________________________
> >
> > If your question is of interest to others as well, please add an entry to the Wiki!
> >
> > maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> >
> > webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> >
> > archive : https://github.com/contextgarden/context
> >
> > wiki : https://wiki.contextgarden.net
> >
> > ___________________________________________________________________________________
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive  : https://github.com/contextgarden/context
> wiki     : https://wiki.contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2024-10-02 23:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-02 22:39 hf
2024-10-02 23:45 ` 黄复雄 [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-10-04 23:03 hf
2024-10-01  6:02 [NTG-context] " ai2472206007
2024-10-02  4:56 ` [NTG-context] " 黄复雄
2024-10-02 11:36   ` ai2472206007

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=CAHN0TNiFZGeU9t1GdY1Cofxndr71hU0CWphmjG5xOBAcWsQG8w@mail.gmail.com \
    --to=aahuaang@gmail.com \
    --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).