Skip to content

Commit

Permalink
improve jukugo-ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
inaniwaudon committed Aug 16, 2022
1 parent 0629b15 commit 662436b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Binary file modified sample/jlreq-jukugo-ruby.pdf
Binary file not shown.
Binary file modified sample/overflow-ruby.pdf
Binary file not shown.
12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,17 @@ const convertJukugoRubys = (
};
applyAttributesToMiddleRubyInfo(newMiddleRuby, middleRuby);
let leftCount = rubyText.length;
// the ruby is only a single character
if (middleRuby.ruby.length === 1) {
// TODO: 中にするとは限らない
newMiddleRuby.alignment = "naka";
leftCount -= maxRubyCounts[0] - 2;
} else {
if (index === 0 && leftCount > 2 && maxRubyCounts[0] > 2) {
} else if (leftCount > 2) {
if (index === 0 && maxRubyCounts[0] > 2) {
newMiddleRuby.alignment = "shita";
leftCount--;
}
if (
index === middleRuby.ruby.length - 1 &&
leftCount > 2 &&
maxRubyCounts[index] > 2
) {
newMiddleRuby.alignment = "kata";
Expand All @@ -393,7 +392,8 @@ const convertJukugoRubys = (
const aki = (leftCount - 2) / 4;
charAttributes.akiLeft = aki;
charAttributes.akiRight = aki;
newMiddleRuby.alignment = "naka";
newMiddleRuby.xOffset =
baseSize * aki * (newMiddleRuby.alignment == "kata" ? -1 : 1);
}
newMiddleRuby.overflow = "false";
resultMiddleRubys.push(newMiddleRuby);
Expand Down Expand Up @@ -427,7 +427,7 @@ const createRubyInfos = (
y: 0,
baseWidth: 0,
baseHeight: 0,
offset: { x: 0, y: 0 },
offset: { x: middleRubyInfo.xOffset ?? 0, y: 0 },
sutegana: middleRubyInfo.sutegana ?? defaultSutegana,
overflow: middleRubyInfo.overflow ?? defaultOverflow,
size: {
Expand Down
1 change: 1 addition & 0 deletions src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface MiddleCommonRubyInfo {
yBaseOutlineIndices: number[];
rubySize?: string;
offset?: string;
xOffset?: number;
font?: string;
alignment?: alignment;
sutegana?: boolean;
Expand Down

0 comments on commit 662436b

Please sign in to comment.