Last active
January 22, 2025 13:59
-
-
Save k16shikano/41f3cedc7042414784ec02d31e56f7cf to your computer and use it in GitHub Desktop.
LuaTeX+Google SansでGoogleロゴ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Product Sansにはリガチャでロゴ全体のグリフ「も」ある | |
\documentclass{standalone} | |
\usepackage{fontspec} | |
\setmonofont{ProductSans-Regular.ttf}[ | |
RawFeature=+calt % Contextual ligatures | |
] | |
\begin{document} | |
\verb|google_logo| | |
\end{document} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Google Sansにはロゴの各文字のグリフがある | |
\documentclass{standalone} | |
\usepackage{fontspec} | |
\usepackage{luacode} | |
\usepackage{xcolor} | |
\setmainfont{GoogleSans-Regular.ttf} | |
\begin{document} | |
\begin{luacode} | |
local font_id = font.current() | |
local glyph_ids = {983070, 983103, 983103, 983101, 983102, 983100} | |
local head = nil | |
local tail = nil | |
for _, gid in ipairs(glyph_ids) do | |
local glyph_node = node.new("glyph") | |
glyph_node.font = font_id | |
glyph_node.char = gid | |
if not head then | |
head = glyph_node | |
tail = glyph_node | |
else | |
tail.next = glyph_node | |
glyph_node.prev = tail | |
tail = glyph_node | |
end | |
end | |
-- 水平ボックスにまとめる | |
local hbox = node.hpack(head) | |
node.write(hbox) | |
\end{luacode} | |
\end{document} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% グリフIDの一覧を取得するのに使ったコード | |
\documentclass{article} | |
\usepackage{fontspec} | |
\usepackage{luacode} | |
\setmainfont{ProductSans-Regular.ttf} | |
\begin{document} | |
\leavevmode | |
\begin{luacode} | |
local font_id = font.current() -- 現在のフォント ID を取得 | |
local font_data = font.getfont(font_id) -- フォントデータを取得 | |
-- ノードリストを構築 | |
local head = nil -- リストの先頭ノード | |
local tail = nil -- 現在の末尾ノード | |
for gid, char_data in pairs(font_data.characters) do | |
-- Glyph ID を表す文字列全体を1つの hbox にまとめる | |
local text = string.format("GID: %d ", gid) | |
local text_head = nil | |
local text_tail = nil | |
for i = 1, #text do | |
local char_node = node.new("glyph") | |
char_node.font = font_id | |
char_node.char = string.byte(text, i) | |
if not text_head then | |
text_head = char_node | |
text_tail = char_node | |
else | |
text_tail.next = char_node | |
char_node.prev = text_tail | |
text_tail = char_node | |
end | |
end | |
local glyph_node = node.new("glyph") | |
glyph_node.font = font_id | |
glyph_node.char = gid | |
text_tail.next = glyph_node | |
text_tail = glyph_node | |
local text_hbox = node.hpack(text_head) -- テキスト全体を1つの hbox にまとめ | |
if not head then | |
head = text_hbox | |
tail = text_hbox | |
else | |
tail.next = text_hbox | |
text_hbox.prev = tail | |
tail = text_hbox | |
end | |
local break_node = node.new("glue") | |
tail.next = break_node | |
break_node.prev = tail | |
tail = break_node | |
end | |
node.write(head) | |
\end{luacode} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment