diff --git a/sample/jlreq-jukugo-ruby.pdf b/sample/jlreq-jukugo-ruby.pdf index f74e123..e5d31f5 100644 Binary files a/sample/jlreq-jukugo-ruby.pdf and b/sample/jlreq-jukugo-ruby.pdf differ diff --git a/sample/overflow-ruby.pdf b/sample/overflow-ruby.pdf index 528177d..d04a0a6 100644 Binary files a/sample/overflow-ruby.pdf and b/sample/overflow-ruby.pdf differ diff --git a/src/main.ts b/src/main.ts index 8454843..99bd147 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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"; @@ -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); @@ -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: { diff --git a/src/ruby.ts b/src/ruby.ts index dc171ce..7678081 100644 --- a/src/ruby.ts +++ b/src/ruby.ts @@ -29,6 +29,7 @@ export interface MiddleCommonRubyInfo { yBaseOutlineIndices: number[]; rubySize?: string; offset?: string; + xOffset?: number; font?: string; alignment?: alignment; sutegana?: boolean;