hide1 commited on
Commit
7eb996b
·
verified ·
1 Parent(s): 361120d

Specify the text color and furigana color together

Browse files
Files changed (1) hide show
  1. index.html +87 -78
index.html CHANGED
@@ -475,7 +475,7 @@ function settings() {
475
  function partStyle(s,g,part) {
476
  const result={...s};
477
  if(part==="ruby"){
478
- result.ink=s.rubyInk;
479
  if(!s.includeRuby) Object.assign(result,{fill:"solid",effect:"flat",outline:"none",bold:false,italic:false,underline:false,strike:false});
480
  }
481
  Object.assign(result,g.format?.[part]);
@@ -635,50 +635,49 @@ el("pasteStyle").onclick=()=>{
635
  syncLocalFields();
636
  };
637
  el("localReset").onclick=()=>{for(const group of editing.groups) group.format=null;syncLocalFields();};
638
- function finishText(s) {
639
- const side = colorText(s.side);
640
- const phrases = {
641
- flat:"", shadow:"A crisp "+side+" shadow falls down and to the right.",
642
- depth:"Solid "+side+" sides extend down and to the right from the letter faces.",
643
- foil:"Metallic foil catches the light in narrow bands across the strokes.",
644
- emboss:"Beveled edges catch light at the upper left and cast shallow inner shadows.",
645
- neon:"Bright tube-like strokes give off a soft "+side+" glow."
646
- };
647
- return phrases[s.effect];
 
 
 
 
 
 
 
648
  }
649
- function decorations(s) {
650
- const a=[];
651
- if(s.fill==="gradient"){
652
- const [start,end]={down:["top","bottom"],across:["left","right"],diagonal:["upper left","lower right"]}[s.direction];
653
- a.push("Fill the letter faces with a smooth gradient from "+colorText(s.ink)+" at the "+start+" to "+colorText(s.gradientEnd)+" at the "+end+".");
654
- }else if(s.fill==="halftone") a.push("Fill the strokes with a fine comic-book halftone dot pattern.");
655
- if (s.bold) a.push("Use extra-heavy strokes.");
656
- if (s.italic) a.push("Slant the letters to the right.");
657
- if (s.underline) a.push("Draw a continuous line just beneath the lettering.");
658
- if (s.strike) a.push("Draw a horizontal strike through the middle of the lettering.");
659
- if (s.outline === "double") a.push("Trace the letters with a "+colorText(s.edge)+" inner outline and a "+colorText(s.outer)+" outer outline.");
660
- else if (s.outline !== "none") a.push("Trace the letters with a "+(s.outline === "thin" ? "fine" : "thick")+" "+colorText(s.edge)+" outline.");
661
- if (s.effect !== "flat") a.push(finishText(s));
662
- return a.join(" ");
663
  }
664
- function rubyText(s,reading) {
665
- const spread=s.align==="spread" && characters(reading).length>1;
666
- return "Use small "+colorText(s.rubyInk)+" furigana directly above the main lettering, about "+Math.round(s.ratio*100)+"% of its height. "+
667
- (spread ? "Space the glyphs evenly from the left edge to the right edge of each annotated word, keeping their natural proportions." : "Center the reading over its corresponding text with natural character spacing.");
668
  }
669
  function ornamentText(s) {
670
  const desc = symbolNames[s.ornament] || "a decorative mark shaped like “"+s.ornament+"”";
671
  return "Place "+desc+" to the right of the title as a separate ornament.";
672
  }
673
- function readingPairs(s) {
 
 
 
 
674
  let offset=0;
675
  return s.groups.flatMap(g=>{
676
- const before=s.base.slice(0,offset);
677
  offset+=g.text.length;
678
- if(!g.reading) return [];
679
- const count=s.base.split(g.text).length-1;
680
- const where=count>1 ? "occurrence "+before.split(g.text).length+" of " : "";
681
- return ["“"+g.reading+"” above "+where+"“"+g.text+"”"];
682
  });
683
  }
684
  function plainPrompt(s) {
@@ -695,50 +694,58 @@ function plainPrompt(s) {
695
  if (s.ornament) text+=", with “"+s.ornament+"” on the right";
696
  return text+".";
697
  }
698
- function scopedPrompt(s){
699
- const lines=["Write “"+s.base+"”.", "Use "+colorText(s.ink)+" "+(s.styleSpec[1]||"lettering")+" by default.",decorations(s)];
700
- let offset=0;
 
 
701
  for(const group of s.groups){
702
- const index=s.base.slice(0,offset).split(group.text).length;
703
- const repeated=s.base.indexOf(group.text)!==s.base.lastIndexOf(group.text);
704
- const target=(repeated?"occurrence "+index+" of ":"")+"“"+group.text+"”";
705
  offset+=group.text.length;
706
- for(const part of ["base","ruby"]){
707
- if(part==="ruby" && !group.reading) continue;
708
- const overrides=group.format?.[part]||{};
709
- if(part==="base" && !Object.keys(overrides).length) continue;
710
- const st=partStyle(s,group,part);
711
- const description=colorText(st.ink)+" "+(st.styleSpec[1]||"lettering");
712
- if(part==="base") lines.push("For "+target+", use "+description+".");
713
- else {
714
- const alignment=st.align==="spread"?"spaced across its width":"centered";
715
- lines.push("Place “"+group.reading+"” directly above "+target+", "+alignment+", in "+description+" at "+Math.round(st.ratio*100)+"% of the base height.");
716
- }
717
- lines.push(decorations(st));
718
- const off={fill:"a solid fill",bold:"regular weight",italic:"upright letters",underline:"no underline",strike:"no strikethrough",outline:"no outline",effect:"a flat finish"};
719
- const exceptions=Object.keys(overrides).filter(k=>k in off && [false,"none","flat","solid"].includes(st[k]));
720
- if(exceptions.length) lines.push("Use "+exceptions.map(k=>off[k]).join(", ")+" here.");
721
  }
722
  }
723
- if(s.ornament) lines.push(ornamentText(s));
724
- return lines.filter(Boolean).join(" ");
 
 
 
 
 
725
  }
726
- function makePrompt(s) {
727
- if(s.groups.some(g=>g.format)) return scopedPrompt(s);
728
- const d=decorations(s);
729
- if (!s.styleSpec[1] && !d && s.ink===defaults.ink && (!s.reading || (s.rubyInk===defaults.ink && s.ratio===.2))) return plainPrompt(s);
730
- const face=s.styleSpec[1] ? " using "+s.styleSpec[1] : "";
731
- const lines=["Render the horizontal title “"+s.base+"” in "+colorText(s.ink)+face+"."];
732
- if (d) lines.push(d);
733
- if (s.reading) {
734
- if (s.groups.length>1) {
735
- lines.push("Place "+readingPairs(s).join(", ")+".");
736
- } else lines.push("The reading is “"+s.reading+"”.");
737
- lines.push(rubyText(s,s.reading));
738
- if (d) lines.push(s.includeRuby ? "Repeat the title treatment on the reading at its smaller scale." : "Keep the reading plain and upright.");
 
 
 
 
 
 
 
 
 
 
739
  }
740
- if (s.ornament) lines.push(ornamentText(s));
741
- return lines.join(" ");
742
  }
743
  const canvas=el("preview"), ctx=canvas.getContext("2d");
744
  function measure(text,size,s,decorated) {
@@ -822,15 +829,17 @@ function frame(box,w,h) {
822
  }
823
  function draftLayout(s,scene,w,h) {
824
  const f=frame(scene.box,w,h);
 
825
  const items=scene.items.map(i=>{
826
  const box=i.box.map((v,j)=>v*f.scale+(j%2 ? f.y : f.x));
827
  if (i.type==="ornament") return {label:"object",caption:ornamentText(s),bbox:box};
828
- const style=i.style;
829
- const caption=[colorText(style.ink)+" "+(style.styleSpec[1]||"lettering")+".",decorations(style)];
830
- if(i.type==="ruby") caption.push(rubyText({...style,rubyInk:style.ink},i.text));
831
- return {label:"text",text:i.text,caption:caption.filter(Boolean).join(" "),bbox:box};
 
832
  });
833
- return {width:w,height:h,bbox_coord_space:"abs",bbox_format:"xyxy",summary:{canvas:"single",caption:makePrompt(s)},items};
834
  }
835
  // Match the official pixel-layout compiler: enclose fractional edges, then center y/x.
836
  function compileLayout(draft) {
 
475
  function partStyle(s,g,part) {
476
  const result={...s};
477
  if(part==="ruby"){
478
+ result.ink=s.linked ? (g.format?.base?.ink ?? s.ink) : s.rubyInk;
479
  if(!s.includeRuby) Object.assign(result,{fill:"solid",effect:"flat",outline:"none",bold:false,italic:false,underline:false,strike:false});
480
  }
481
  Object.assign(result,g.format?.[part]);
 
635
  syncLocalFields();
636
  };
637
  el("localReset").onclick=()=>{for(const group of editing.groups) group.format=null;syncLocalFields();};
638
+ // Describe visible differences only. Colors belonging to inactive effects are omitted.
639
+ function appearance(s, ruby=false){
640
+ const color=colorText(s.ink);
641
+ const direction={down:"top to bottom",across:"left to right",diagonal:"upper left to lower right"};
642
+ const fill=s.fill==="gradient" ? color+" to "+colorText(s.gradientEnd)+" gradient ("+direction[s.direction]+")"
643
+ : s.fill==="halftone" ? color+" halftone dots" : color;
644
+ const face={plain:"",mincho:"Mincho",gothic:"Japanese Gothic",round:"rounded Gothic",pop:"chunky pop",brush:"brush lettering",
645
+ pixel:"pixel lettering",led:"LED dot-matrix",digital:"angular digital",segments:"seven-segment",stencil:"stencil",
646
+ hollow:"hollow lettering",balloon:"inflated balloon lettering",pen:"handwritten"};
647
+ const outline=s.outline==="double" ? colorText(s.edge)+" inner and "+colorText(s.outer)+" outer outlines"
648
+ : s.outline==="none" ? "" : (s.outline==="thin"?"thin ":"thick ")+colorText(s.edge)+" outline";
649
+ const side=colorText(s.side);
650
+ return {fill,style:face[s.style],outline,
651
+ effect:{flat:"",depth:side+" 3D extrusion",shadow:side+" drop shadow",neon:side+" neon glow",foil:"metallic foil",emboss:"embossed"}[s.effect],
652
+ bold:s.bold?"bold":"",italic:s.italic?"italic":"",underline:s.underline?"underlined":"",strike:s.strike?"strikethrough":"",
653
+ align:ruby && s.align==="center"?"centered":"",
654
+ ratio:ruby && s.ratio!==.2?Math.round(s.ratio*100)+"% of the base height":""};
655
  }
656
+ const plainAppearance=appearance({...defaults,style:"plain"});
657
+ const resetWords={style:"plain lettering",outline:"no outline",effect:"flat finish",bold:"regular weight",italic:"upright",
658
+ underline:"no underline",strike:"no strikethrough",align:"spread across the word",ratio:"20% of the base height"};
659
+ function differences(current,inherited){
660
+ return Object.keys(current).filter(k=>current[k]!==inherited[k]);
 
 
 
 
 
 
 
 
 
661
  }
662
+ function styleInstruction(target,look,keys){
663
+ if(!keys.length)return "";
664
+ if(keys.length===1 && keys[0]==="fill" && palette.some(c=>c[2]===look.fill))return "Color "+target+" "+look.fill+".";
665
+ return "Use "+keys.map(k=>look[k]||resetWords[k]).join(", ")+" for "+target+".";
666
  }
667
  function ornamentText(s) {
668
  const desc = symbolNames[s.ornament] || "a decorative mark shaped like “"+s.ornament+"”";
669
  return "Place "+desc+" to the right of the title as a separate ornament.";
670
  }
671
+ function wordTarget(s,g,offset,color=""){
672
+ const repeated=s.base.indexOf(g.text)!==s.base.lastIndexOf(g.text);
673
+ return (repeated?"occurrence "+s.base.slice(0,offset).split(g.text).length+" of ":"")+(color?color+" ":"")+"“"+g.text+"”";
674
+ }
675
+ function readingPairs(s){
676
  let offset=0;
677
  return s.groups.flatMap(g=>{
678
+ const target=wordTarget(s,g,offset);
679
  offset+=g.text.length;
680
+ return g.reading?["“"+g.reading+"” above "+target]:[];
 
 
 
681
  });
682
  }
683
  function plainPrompt(s) {
 
694
  if (s.ornament) text+=", with “"+s.ornament+"” on the right";
695
  return text+".";
696
  }
697
+ function scopedColorPrompt(s){
698
+ if(s.fill!=="solid" || !s.groups.some(({format})=>format?.base?.ink || format?.ruby?.ink)) return null;
699
+ const name=ink=>ink===defaults.ink?"black":colorText(ink);
700
+ const wordColors=[], readings=[];
701
+ let hasLocalRubyColor=false, offset=0;
702
  for(const group of s.groups){
703
+ const start=offset;
 
 
704
  offset+=group.text.length;
705
+ if(!group.reading && !group.format) continue;
706
+ const word=partStyle(s,group,"base"), ruby=partStyle(s,group,"ruby");
707
+ if(word.fill!=="solid" || (group.reading && ruby.fill!=="solid")) return null;
708
+ const wordHasColor=word.ink!==s.ink;
709
+ const target=wordTarget(s,group,start,wordHasColor?"":name(word.ink));
710
+ if(wordHasColor) wordColors.push(target+" in "+name(word.ink));
711
+ if(group.reading){
712
+ hasLocalRubyColor ||= ruby.ink!==s.rubyInk;
713
+ readings.push("small "+name(ruby.ink)+" “"+group.reading+"” above "+target);
 
 
 
 
 
 
714
  }
715
  }
716
+ if(!wordColors.length && !hasLocalRubyColor) return null;
717
+ const colors=wordColors.join(" and ");
718
+ let text=plainPrompt({...s,reading:""}).replace(/([。!?.!?]”)\.$/,"$1")+" Set ";
719
+ text+=wordColors.length===s.groups.length ? colors : "the text in "+name(s.ink)+(colors?", with "+colors:"");
720
+ text+=".";
721
+ if(readings.length) text+=" Place "+readings.join(" and ")+".";
722
+ return text;
723
  }
724
+ function makePrompt(s){
725
+ const base=appearance(s), ruby=appearance(partStyle(s,{},"ruby"),true);
726
+ const scoped=scopedColorPrompt(s);
727
+ const lines=[scoped ?? plainPrompt(s)];
728
+ const keepKey=k=>!scoped || k!=="fill";
729
+ const mainKeys=differences(base,plainAppearance).filter(keepKey), rubyKeys=s.reading?differences(ruby,plainAppearance).filter(keepKey):[];
730
+ const shared=mainKeys.filter(k=>rubyKeys.includes(k) && base[k]===ruby[k]);
731
+ lines.push(styleInstruction("all lettering",base,shared),
732
+ styleInstruction("the main text",base,mainKeys.filter(k=>!shared.includes(k))),
733
+ styleInstruction("the furigana",ruby,rubyKeys.filter(k=>!shared.includes(k) && !(k==="align" && !scoped && s.groups.length===1))));
734
+ let offset=0;
735
+ for(const group of s.groups){
736
+ const start=offset;
737
+ offset+=group.text.length;
738
+ if(!group.format) continue;
739
+ const target=wordTarget(s,group,start);
740
+ const word=partStyle(s,group,"base"), reading=partStyle(s,group,"ruby");
741
+ const wordLook=appearance(word);
742
+ lines.push(styleInstruction(target,wordLook,differences(wordLook,base).filter(keepKey)));
743
+ if(group.reading){
744
+ const readingLook=appearance(reading,true);
745
+ lines.push(styleInstruction("the furigana “"+group.reading+"” above "+target,readingLook,differences(readingLook,ruby).filter(keepKey)));
746
+ }
747
  }
748
+ return lines.filter(Boolean).join(" ");
 
749
  }
750
  const canvas=el("preview"), ctx=canvas.getContext("2d");
751
  function measure(text,size,s,decorated) {
 
829
  }
830
  function draftLayout(s,scene,w,h) {
831
  const f=frame(scene.box,w,h);
832
+ const mixedInk=new Set(scene.items.filter(i=>i.type!=="ornament").map(i=>i.style.ink)).size>1;
833
  const items=scene.items.map(i=>{
834
  const box=i.box.map((v,j)=>v*f.scale+(j%2 ? f.y : f.x));
835
  if (i.type==="ornament") return {label:"object",caption:ornamentText(s),bbox:box};
836
+ const isRuby=i.type==="ruby", look=appearance(i.style,isRuby);
837
+ const keys=differences(look,plainAppearance);
838
+ if(mixedInk && !keys.includes("fill"))keys.unshift("fill");
839
+ const caption=[isRuby?"furigana":"main text",...keys.map(k=>look[k])].join(", ");
840
+ return {label:"text",text:i.text,caption,bbox:box};
841
  });
842
+ return {width:w,height:h,bbox_coord_space:"abs",bbox_format:"xyxy",summary:{canvas:"single",caption:plainPrompt(s)},items};
843
  }
844
  // Match the official pixel-layout compiler: enclose fractional edges, then center y/x.
845
  function compileLayout(draft) {