Spaces:
Running
Running
Specify the text color and furigana color together
Browse files- 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 |
-
|
| 639 |
-
|
| 640 |
-
const
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
}
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 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
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
let offset=0;
|
| 675 |
return s.groups.flatMap(g=>{
|
| 676 |
-
const
|
| 677 |
offset+=g.text.length;
|
| 678 |
-
|
| 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
|
| 699 |
-
|
| 700 |
-
|
|
|
|
|
|
|
| 701 |
for(const group of s.groups){
|
| 702 |
-
const
|
| 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 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 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(
|
| 724 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 725 |
}
|
| 726 |
-
function makePrompt(s)
|
| 727 |
-
|
| 728 |
-
const
|
| 729 |
-
|
| 730 |
-
const
|
| 731 |
-
const
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
}
|
| 740 |
-
|
| 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
|
| 829 |
-
const
|
| 830 |
-
if(
|
| 831 |
-
|
|
|
|
| 832 |
});
|
| 833 |
-
return {width:w,height:h,bbox_coord_space:"abs",bbox_format:"xyxy",summary:{canvas:"single",caption:
|
| 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) {
|