The Wrenhall · Food & Beverage

Menu Studio

Type the dishes and prices, choose the size and the design, and download a print-ready menu. Capitals, prices, dashes and the dietary key are set to the Wrenhall standard for you. Nothing to install; it works offline.

Size and design

The heading

Today’s special prints in a box under the heading

Sections and dishes

Type freely: “28.00”, “$28” and “28” all print the same way, and titles follow the house style. Marks: V vegetarian, VG vegan, GF gluten-free, N contains nuts, S spicy, ★ signature. Only the marks you use appear in the key.

Small print

Photograph used by the Photo design

ST.menus[m.id])) ST=fresh(); const M=()=>ST.menus[ST.current]; function save(){ try{ localStorage.setItem(KEY,JSON.stringify(ST)); }catch(e){} } /* ---------------- house style ---------------- */ const SMALL=new Set(["a","an","and","as","at","but","by","for","from","in","of","on","or","the","to","with","vs","de","la","du","en"]); function clean(s){ return String(s||"").replace(/\s+/g," ").trim() .replace(/ - /g," – ").replace(/--/g,"–").replace(/\.\.\./g,"…") .replace(/(\w)'(\w)/g,"$1’$2").replace(/'/g,"’"); } function titleCase(s){ s=clean(s); if(!s) return ""; return s.split(" ").map((w,i)=>{ if(/^[A-Z0-9&]{2,4}$/.test(w)) return w; // GF, BBQ, 8 oz stays const lw=w.toLowerCase(); if(i>0 && SMALL.has(lw)) return lw; return lw.replace(/^(\P{L}*)(\p{L})/u,(m,a,b)=>a+b.toUpperCase()).replace(/-(\p{L})/gu,(m,b)=>"-"+b.toUpperCase()); }).join(" "); } function sentence(s){ s=clean(s).replace(/[.;,]+$/,""); return s ? s[0].toUpperCase()+s.slice(1) : ""; } function price(s){ s=clean(s).replace(/[$£€]/g,"").replace(/\s*\/\s*/g," / "); return s.replace(/\d+(?:\.\d+)?/g,n=>{ const v=parseFloat(n); return Number.isInteger(v)?String(v):v.toFixed(2); }); } const nameStyle=d=>d==="classic"?"title":"title"; /* ---------------- drawing: one painter for the proof and the file ---------------- */ const MMPT=25.4/72; function Pen(ctx,scale,dry){ const px=pt=>pt*MMPT*scale; const api={ font(o){ ctx.font=(o.italic?"italic ":"")+(o.weight||400)+" "+px(o.pt)+"px \""+(o.exp?EXP:SANS)+"\""; }, w(t,o){ api.font(o); const tr=(o.track||0)/1000*px(o.pt); return (ctx.measureText(t).width+Math.max(0,t.length-1)*tr)/scale; }, lines(t,wmm,o){ const words=String(t).split(" ").filter(Boolean), out=[]; let cur=""; words.forEach(w=>{ const tr=cur?cur+" "+w:w; if(cur&&api.w(tr,o)>wmm){ out.push(cur); cur=w; } else cur=tr; }); if(cur) out.push(cur); return out; }, lh:o=>(o.lead||o.pt*1.3)*MMPT, /* one line made of runs in different styles, aligned in [x, x+w] */ runs(rs,x,y,w,align,lh){ const ws=rs.map(r=>api.w(r.t,r)); const total=ws.reduce((a,b)=>a+b,0); let cx = align==="center" ? x+(w-total)/2 : align==="right" ? x+w-total : x; if(!dry) rs.forEach((r,i)=>{ api.draw(r.t,cx,y,r,lh); cx+=ws[i]; }); return total; }, draw(t,x,y,o,lh){ api.font(o); ctx.fillStyle=o.color||C.navy; ctx.textBaseline="alphabetic"; const base=(y+ (lh||api.lh(o))*0.78)*scale, tr=(o.track||0)/1000*px(o.pt); if(!tr){ ctx.fillText(t,x*scale,base); return; } let cx=x*scale; for(const ch of t){ ctx.fillText(ch,cx,base); cx+=ctx.measureText(ch).width+tr; } }, /* wrapped paragraph; returns the y below it */ text(t,x,y,w,o){ const ls=api.lines(o.caps?String(t).toUpperCase():t,w,o), lh=api.lh(o); ls.forEach(l=>{ if(!dry){ const lw=api.w(l,o); const dx=o.align==="center"?x+(w-lw)/2:o.align==="right"?x+w-lw:x; api.draw(l,dx,y,o,lh); } y+=lh; }); return y; }, rect(x,y,w,h,col){ if(dry) return; ctx.fillStyle=col; ctx.fillRect(x*scale,y*scale,w*scale,h*scale); }, frame(x,y,w,h,col,lw){ if(dry) return; ctx.strokeStyle=col; ctx.lineWidth=Math.max(1,lw*scale); ctx.strokeRect(x*scale,y*scale,w*scale,h*scale); }, diamond(cx,cy,r,col){ if(dry) return; ctx.fillStyle=col; ctx.beginPath(); ctx.moveTo(cx*scale,(cy-r)*scale); ctx.lineTo((cx+r)*scale,cy*scale); ctx.lineTo(cx*scale,(cy+r)*scale); ctx.lineTo((cx-r)*scale,cy*scale); ctx.closePath(); ctx.fill(); }, mono(cx,y,h,col){ if(dry) return; const p=new Path2D(P.mono); const s=h/1953.44*scale; ctx.save(); ctx.translate((cx-h*1.0238/2)*scale,y*scale); ctx.scale(s,s); ctx.fillStyle=col; ctx.fill(p); ctx.restore(); }, img(im,x,y,w,h){ if(dry||!im) return; const ar=im.naturalWidth/im.naturalHeight, box=w/h; let sw,sh; if(ar>box){ sh=h; sw=h*ar; } else { sw=w; sh=w/ar; } ctx.save(); ctx.beginPath(); ctx.rect(x*scale,y*scale,w*scale,h*scale); ctx.clip(); ctx.drawImage(im,(x+(w-sw)/2)*scale,(y+(h-sh)/2)*scale,sw*scale,sh*scale); ctx.restore(); }, shade(x,y,w,h){ if(dry) return; const g=ctx.createLinearGradient(0,y*scale,0,(y+h)*scale); g.addColorStop(0,"rgba(0,0,0,0)"); g.addColorStop(1,"rgba(0,0,0,.55)"); ctx.fillStyle=g; ctx.fillRect(x*scale,y*scale,w*scale,h*scale); } }; return api; } let PHOTO=null, PHOTO_SRC=""; function photoSrc(m){ return m.photoData || P.images[m.photo] || ""; } /* The page, measured and drawn by the same code. k scales the type when a menu is long. */ function paint(ctx,scale,m,k,dry,two){ const F=FORMATS[m.format], W=F.w, H=F.h, pen=Pen(ctx,scale,dry), d=m.design; const big=W>=200, small=W<120; k=k*(big?1.2:small?0.95:1); // the base size follows the sheet const mx = small?9:big?18:13; // side margin const paper = d==="column" ? C.lav : "#ffffff"; pen.rect(0,0,W,H,paper); const used=new Set(); let sigUsed=false; m.sections.forEach(s=>s.items.forEach(it=>{ (it.marks||[]).forEach(x=>used.add(x)); if(it.sig) sigUsed=true; })); if(m.special&&m.special.on) (m.special.marks||[]).forEach(x=>used.add(x)); /* ---- heading ---- */ let y; const venue=clean(m.venue), title=clean(m.title); const vpt = (big?26:small?17:21)*(d==="column"?1.05:1); if(d==="photo"){ const ph=big?104:small?64:74; if(PHOTO) pen.img(PHOTO,0,0,W,ph); else pen.rect(0,0,W,ph,C.blue); pen.shade(0,ph*0.35,W,ph*0.65); let ty=ph-(big?36:small?27:30); pen.mono(W/2,ty-(big?13:10),big?10:8,"#ffffff"); ty=pen.text(venue,mx,ty,W-2*mx,{pt:vpt,exp:true,weight:500,caps:true,track:small?120:180,align:"center",color:"#ffffff",lead:vpt*1.1}); pen.text(title,mx,ty+1.5,W-2*mx,{pt:7.5,weight:600,caps:true,track:260,align:"center",color:"#ffffff"}); y=ph+7; }else if(d==="classic"){ pen.frame(5,5,W-10,H-10,C.gold,0.35); y=small?14:big?20:16; pen.mono(W/2,y,big?12:9,C.gold); y+=big?17:13; y=pen.text(venue,mx,y,W-2*mx,{pt:vpt,exp:true,weight:500,caps:true,track:small?110:170,align:"center",color:C.navy,lead:vpt*1.12}); y=pen.text(title,mx,y+1.5,W-2*mx,{pt:7.5,weight:600,caps:true,track:280,align:"center",color:C.gold})+3; }else{ y=small?12:big?18:14; pen.mono(mx+5,y,10,C.gold); y+=15; y=pen.text(venue,mx,y,W-2*mx,{pt:vpt*1.08,exp:true,weight:500,color:C.navy,lead:vpt*1.16}); y=pen.text(title,mx,y+1,W-2*mx,{pt:7.5,weight:700,caps:true,track:240,color:C.gold})+2.5; } const al = d==="column" ? "left" : "center"; const sub=[clean(m.note), m.dateOn?clean(m.dateText):""].filter(Boolean).join(" · "); if(sub) y=pen.text(sub,mx,y,W-2*mx,{pt:7.2,weight:500,align:al,color:"#6E6E73",track:20})+1; if(clean(m.priceLine)) y=pen.text(clean(m.priceLine),mx,y+0.6,W-2*mx,{pt:9.5,exp:true,weight:500,italic:EXP!=="Jost",align:al,color:C.navy})+1; y+=big?5:3.5; /* ---- foot: the key, the small print, the place ---- */ const footW=W-2*mx; const keyBits=MARKS.filter(x=>used.has(x[0])).map(x=>x[0]+" "+x[1]); if(sigUsed) keyBits.unshift("★ "+(clean(m.sigLabel)||"signature").toLowerCase()); const foot=[]; if(keyBits.length) foot.push({t:keyBits.join(" · "),o:{pt:6.6,weight:600,align:"center",color:C.navy}}); if(clean(m.footer)) foot.push({t:clean(m.footer),o:{pt:6.4,align:"center",color:"#6E6E73"}}); foot.push({t:P.place,o:{pt:6,weight:600,caps:true,track:160,align:"center",color:C.gold}}); const footDry=Pen(ctx,scale,true); let fh=0; foot.forEach(f=>{ fh=footDry.text(f.t,mx,fh,footW,f.o)+0.8; }); const bottom=H-(d==="classic"?12:9); let fy=bottom-fh; const limit=fy-4; foot.forEach(f=>{ fy=pen.text(f.t,mx,fy,footW,f.o)+0.8; }); /* ---- the special ---- */ if(m.special&&m.special.on&&clean(m.special.text)){ const sp=m.special, bw=Math.min(W-2*mx, big?120:W-2*mx), bx=(W-bw)/2, pad=3.5; const inner=bw-2*pad, mdry=Pen(ctx,scale,true); const ho={pt:6.8,weight:700,caps:true,track:220,align:"center",color:C.gold}; const to={pt:9.5*k,exp:true,weight:500,align:"center",color:C.navy}; const po={pt:8.5*k,weight:700,align:"center",color:C.gold}; let h=pad; h=mdry.text(clean(sp.head)||"Today’s special",bx+pad,h,inner,ho)+0.8; h=mdry.text(sentence(sp.text),bx+pad,h,inner,to); if(m.showPrices&&price(sp.price)) h=mdry.text(price(sp.price),bx+pad,h+0.5,inner,po); h+=pad; pen.frame(bx,y,bw,h,C.gold,0.35); let yy=y+pad; yy=pen.text(clean(sp.head)||"Today’s special",bx+pad,yy,inner,ho)+0.8; yy=pen.text(sentence(sp.text),bx+pad,yy,inner,to); if(m.showPrices&&price(sp.price)) pen.text(price(sp.price),bx+pad,yy+0.5,inner,po); y+=h+(big?7:5); } /* ---- the body: blocks, flowed into one or two columns ---- */ const cols = ((d==="column"&&big)||two) ? 2 : 1, gut=10; const cw=(W-2*mx-(cols-1)*gut)/cols; const center = d!=="column"; const blocks=[]; const sp=(big?1:0.85)*k; const mk=it=>(it.marks||[]).filter(Boolean); const mdry=Pen(ctx,scale,true); m.sections.forEach((s,si)=>{ const head={pt:(center?9.5:9)*k,weight:center?500:700,exp:center,caps:true,track:center?240:200,align:center?"center":"left",color:center?C.gold:C.navy}; const items=s.items.filter(it=>clean(it.name)); if(!clean(s.title)&&!items.length) return; const hb={keep:true,draw:(x,yy,P2)=>{ let h=0; if(center){ P2.diamond(x+cw/2,yy+1.6,1.1*k,C.gold); h+=4.2*k; } h=P2.text(clean(s.title),x,yy+h,cw,head)-yy; if(clean(s.note)) h=P2.text(sentence(s.note),x,yy+h+0.4,cw,{pt:7*k,italic:true,align:head.align,color:"#6E6E73"})-yy; return h+3.2*sp; }}; hb.h=hb.draw(0,0,mdry); if(si>0) hb.gap=(big?6:4.5)*k; blocks.push(hb); items.forEach(it=>{ const name=titleCase(it.name), pr=m.showPrices?price(it.price):"", marks=mk(it); const no={pt:10*k,exp:center,weight:center?500:700,color:C.navy}; const mo={pt:6.3*k,weight:700,color:C.gold,track:40}; const po={pt:9*k,weight:700,color:C.gold}; const dO={pt:7.6*k,italic:center,color:"#55555A",align:center?"center":"left",lead:7.6*k*1.32}; const b={draw:(x,yy,P2)=>{ let h=0; if(it.sig){ h=P2.text("★ "+(clean(m.sigLabel)||"Signature"),x,yy,cw,{pt:5.8*k,weight:700,caps:true,track:200,color:C.gold,align:center?"center":"left"})-yy+0.3; } const lh=P2.lh(no); const mtxt=marks.length?" "+marks.join(" "):""; if(center){ const one=[{t:name,...no}].concat(mtxt?[{t:mtxt,...mo}]:[]).concat(pr?[{t:" "+pr,...po}]:[]); const tw=one.reduce((a,r)=>a+P2.w(r.t,r),0); if(tw<=cw){ P2.runs(one,x,yy+h,cw,"center",lh); h+=lh; } else { h=P2.text(name,x,yy+h,cw,Object.assign({align:"center"},no))-yy; const two=(mtxt?[{t:mtxt.trim(),...mo}]:[]).concat(pr?[{t:(mtxt?" ":"")+pr,...po}]:[]); if(two.length){ P2.runs(two,x,yy+h,cw,"center",lh); h+=lh; } } }else{ const pw=pr?P2.w(pr,po)+3:0; const nl=P2.lines(name,cw-pw-(mtxt?P2.w(mtxt,mo):0),no); nl.forEach((l,i)=>{ const r=[{t:l,...no}]; if(i===nl.length-1&&mtxt) r.push({t:mtxt,...mo}); P2.runs(r,x,yy+h,cw-pw,"left",lh); if(i===0&&pr) P2.runs([{t:pr,...po}],x,yy+h,cw,"right",lh); h+=lh; }); } const desc=sentence(it.desc); if(desc) h=P2.text(desc,x+(center?0:0),yy+h+0.3,center?cw:cw-(pr?14:0),dO)-yy; return h+3.4*sp; }}; b.h=b.draw(0,0,mdry); blocks.push(b); }); }); // place: one column top to bottom, or two columns balanced at a section break const top=y, avail=limit-top; const colH=arr=>arr.reduce((h,b,j)=>h+(j>0&&b.gap?b.gap:0)+b.h,0); const placed=[]; let over=false, usedH=0; const stack=(arr,x)=>{ let cy=top; arr.forEach((b,j)=>{ const g=(j>0&&b.gap)?b.gap:0; placed.push({b,x,y:cy+g}); cy+=g+b.h; }); return cy-top; }; if(cols===2&&blocks.length>1){ let best=null; for(let i=1;iavail+0.5; const shift = !over ? Math.max(0,Math.min((avail-usedH)/2, center?60:0)) : 0; /* nothing is printed over the small print: what does not fit stays off the page, and Checks says so */ placed.forEach(p=>{ if(p.y+p.b.h+shift<=limit+0.5) p.b.draw(p.x,p.y+shift,pen); }); const cy=top+usedH; return {over, k, fill:(cy-top)/avail, blocks:blocks.length}; } /* tightest first fit */ const LADDER=[1,0.96,0.92,0.88,0.84,0.8,0.76,0.72]; let _mc=null; function fitK(m){ if(!_mc){ _mc=document.createElement("canvas"); _mc.width=_mc.height=4; } const ctx=_mc.getContext("2d"), wide=FORMATS[m.format].w>=200 && m.design!=="column"; /* one column while the type stays comfortable; on A4 a long menu then goes to two columns */ for(const k of LADDER){ if(wide&&k<0.84) break; if(!paint(ctx,4,m,k,true,false).over) return {k,two:false,over:false}; } if(wide) for(const k of LADDER){ if(!paint(ctx,4,m,k,true,true).over) return {k,two:true,over:false}; } return {k:LADDER[LADDER.length-1],two:wide,over:true}; } /* ---------------- proof ---------------- */ let FIT={k:1,over:false}; function render(){ const m=M(), F=FORMATS[m.format], cv=$("#proof"), box=$("#proofBox"); const maxW=Math.max(260,box.clientWidth-36), maxH=Math.max(420,window.innerHeight-210); const css=Math.min(maxW, maxH*F.w/F.h), dpr=window.devicePixelRatio||1; cv.style.width=css+"px"; cv.style.height=(css*F.h/F.w)+"px"; cv.width=Math.round(css*dpr); cv.height=Math.round(css*F.h/F.w*dpr); FIT=fitK(m); paint(cv.getContext("2d"),cv.width/F.w,m,FIT.k,false,FIT.two); flags(m); $("#fmtlabel").textContent=F.label; const n=m.sections.reduce((a,s)=>a+s.items.length,0); $("#count").textContent=m.sections.length+" sections · "+n+" dishes"; $("#meta").textContent=clean(m.venue)+" · "+clean(m.title)+" · "+F.label+" · "+DESIGNS[m.design].split(" · ")[0]+(FIT.k<1?" · type at "+Math.round(FIT.k*100)+"%":""); } let _q=0; function later(){ clearTimeout(_q); _q=setTimeout(()=>{ save(); render(); },30); } function flags(m){ const out=[]; if(FIT.over) out.push(["err","The menu does not fit on the "+m.format+" "+(m.format==="A4"?"page":"card")+", even with the type at its smallest. Shorten a description, take a dish out, or choose a larger size."]); m.sections.forEach(s=>s.items.forEach(it=>{ const n=titleCase(it.name)||"A dish"; if(!clean(it.name)&&(clean(it.desc)||clean(it.price))) out.push(["warn","A dish in “"+(clean(s.title)||"a section")+"” has no name, so it is left off the menu."]); if(m.showPrices&&clean(it.name)&&!price(it.price)) out.push(["warn",n+" has no price."]); if(clean(it.desc).length>130) out.push(["warn",n+": the description is long ("+clean(it.desc).length+" characters). Menus read best under 100."]); })); if(m.special&&m.special.on&&!clean(m.special.text)) out.push(["warn","Today’s special is ticked but empty."]); if(m.design==="photo"&&!PHOTO) out.push(["warn","The Photo design has no photograph yet."]); if(!out.some(x=>x[0]==="err")){ if(FIT.k<1) out.push(["info","The type is set at "+Math.round(FIT.k*100)+"% so everything fits. A larger size gives it more room."]); if(!out.length) out.push(["ok","Everything is in order. The menu is ready to download."]); } $("#flags").innerHTML=out.map(f=>'
'+esc(f[1])+'
').join(""); } const esc=s=>String(s).replace(/[&<>"]/g,c=>({"&":"&","<":"<",">":">",'"':"""}[c])); /* ---------------- the form ---------------- */ function loadPhoto(cb){ const src=photoSrc(M()); if(!src){ PHOTO=null; PHOTO_SRC=""; cb&&cb(); return; } if(src===PHOTO_SRC&&PHOTO){ cb&&cb(); return; } const im=new Image(); im.onload=()=>{ PHOTO=im; PHOTO_SRC=src; cb&&cb(); }; im.onerror=()=>{ PHOTO=null; cb&&cb(); }; im.src=src; } function fillForm(){ const m=M(); $("#tabs").innerHTML=P.menus.map(x=>{ const s=ST.menus[x.id]; return ''; }).join(""); $("#format").innerHTML=Object.entries(FORMATS).map(([k,v])=>'').join(""); $("#design").innerHTML=Object.entries(DESIGNS).map(([k,v])=>'').join(""); $("#format").value=m.format; $("#design").value=m.design; $("#showPrices").checked=!!m.showPrices; $("#specialOn").checked=!!(m.special&&m.special.on); $("#dateOn").checked=!!m.dateOn; ["venue","note","dateText","priceLine","sigLabel","footer"].forEach(k=>{ $("#"+k).value=m[k]||""; }); $("#mtitle").value=m.title||""; const sp=m.special||{}; $("#spHead").value=sp.head||""; $("#spText").value=sp.text||""; $("#spPrice").value=sp.price||""; $("#specialCard").style.display=$("#specialOn").checked?"":"none"; $("#photoNote").textContent=m.photoData?"Your own photo is in use on this computer.":"The standard photo for "+clean(m.venue)+" is in use (Pexels)."; sections(); } function sections(){ const m=M(); $("#sections").innerHTML=m.sections.map((s,si)=> '
' +'
' +'
' +s.items.map((it,ii)=>'
' +'' +'' +'
' +'' +'
'+MARKS.map(x=>'').join("") +'
').join("") +'
').join(""); } document.addEventListener("input",e=>{ const m=M(), t=e.target; if(t.closest("#sections")){ const si=+t.closest(".sec").dataset.s; if(t.dataset.f){ m.sections[si][t.dataset.f]=t.value; } else if(t.dataset.g){ const ii=+t.closest(".item").dataset.i; m.sections[si].items[ii][t.dataset.g]=t.value; } return later(); } if(["venue","note","dateText","priceLine","sigLabel","footer"].includes(t.id)){ m[t.id]=t.value; return later(); } if(t.id==="mtitle"){ m.title=t.value; return later(); } if(["spHead","spText","spPrice"].includes(t.id)){ m.special=m.special||{}; m.special[{spHead:"head",spText:"text",spPrice:"price"}[t.id]]=t.value; return later(); } }); document.addEventListener("change",e=>{ const m=M(), t=e.target; if(t.id==="format"){ m.format=t.value; } else if(t.id==="design"){ m.design=t.value; } else if(t.id==="showPrices"){ m.showPrices=t.checked; } else if(t.id==="specialOn"){ m.special=m.special||{}; m.special.on=t.checked; $("#specialCard").style.display=t.checked?"":"none"; } else if(t.id==="dateOn"){ m.dateOn=t.checked; } else return; later(); }); document.addEventListener("click",e=>{ const b=e.target.closest("button"); if(!b) return; const m=M(); if(b.dataset.menu){ ST.current=b.dataset.menu; save(); fillForm(); loadPhoto(render); return; } const sec=b.closest(".sec"); const si=sec?+sec.dataset.s:-1; if(b.dataset.mk||b.dataset.sig){ const it=m.sections[si].items[+b.closest(".item").dataset.i]; if(b.dataset.sig){ it.sig=!it.sig; b.setAttribute("aria-pressed",String(it.sig)); } else { it.marks=it.marks||[]; const k=b.dataset.mk, i=it.marks.indexOf(k); if(i<0) it.marks.push(k); else it.marks.splice(i,1); b.setAttribute("aria-pressed",String(i<0)); } return later(); } const a=b.dataset.act; if(!a) return; const S2=m.sections; if(a==="add"){ S2[si].items.push({name:"",desc:"",price:"",marks:[]}); } else if(a==="sup"&&si>0){ [S2[si-1],S2[si]]=[S2[si],S2[si-1]]; } else if(a==="sdown"&&si0) [L[ii-1],L[ii]]=[L[ii],L[ii-1]]; if(a==="down"&&ii{ M().sections.push({title:"New section",note:"",items:[{name:"",desc:"",price:"",marks:[]}]}); sections(); later(); }); $("#reset").addEventListener("click",()=>{ const id=ST.current; ST.menus[id]=JSON.parse(JSON.stringify(P.menus.find(x=>x.id===id))); save(); fillForm(); loadPhoto(render); }); $("#photoBtn").addEventListener("click",()=>$("#photoFile").click()); $("#photoFile").addEventListener("change",e=>{ const f=e.target.files[0]; if(!f) return; const r=new FileReader(); r.onload=()=>{ M().photoData=r.result; save(); fillForm(); loadPhoto(render); }; r.readAsDataURL(f); }); $("#photoReset").addEventListener("click",()=>{ delete M().photoData; save(); fillForm(); loadPhoto(render); }); window.addEventListener("resize",()=>later()); /* ---------------- the files ---------------- */ function pageCanvas(){ const m=M(), F=FORMATS[m.format], s=300/25.4, c=document.createElement("canvas"); c.width=Math.round(F.w*s); c.height=Math.round(F.h*s); paint(c.getContext("2d"),s,m,FIT.k,false,FIT.two); return c; } function fileName(ext){ const m=M(); return (clean(m.venue)+" "+clean(m.title)+" "+m.format).replace(/[\\/:*?"<>|]/g,"")+"."+ext; } function save_(blob,name){ const a=document.createElement("a"); a.href=URL.createObjectURL(blob); a.download=name; document.body.appendChild(a); a.click(); a.remove(); setTimeout(()=>URL.revokeObjectURL(a.href),4000); } function pdfFrom(c){ const F=FORMATS[M().format], d=c.toDataURL("image/jpeg",0.92), bin=atob(d.split(",")[1]); const img=new Uint8Array(bin.length); for(let i=0;i{ const b=typeof x==="string"?enc.encode(x):x; parts.push(b); len+=b.length; }; put("%PDF-1.4\n"); const obj=(n,s)=>{ offs[n]=len; put(n+" 0 obj\n"+s+"\nendobj\n"); }; obj(1,"<>"); obj(2,"<>"); obj(3,"<>>>/Contents 5 0 R>>"); offs[4]=len; put("4 0 obj\n<>\nstream\n"); put(img); put("\nendstream\nendobj\n"); const cs="q "+W+" 0 0 "+H+" 0 0 cm /Im0 Do Q"; obj(5,"<>\nstream\n"+cs+"\nendstream"); const x=len; put("xref\n0 6\n0000000000 65535 f \n"+[1,2,3,4,5].map(n=>String(offs[n]).padStart(10,"0")+" 00000 n \n").join("")+"trailer\n<>\nstartxref\n"+x+"\n%%EOF\n"); return new Blob(parts,{type:"application/pdf"}); } $("#dlPdf").addEventListener("click",()=>{ if(FIT.over){ flags(M()); } save_(pdfFrom(pageCanvas()),fileName("pdf")); }); $("#dlJpg").addEventListener("click",()=>{ pageCanvas().toBlob(b=>save_(b,fileName("jpg")),"image/jpeg",0.92); }); /* go */ fillForm(); const ready=document.fonts?Promise.all([SANS,EXP].flatMap(f=>["400","500","600","700"].map(w=>document.fonts.load(w+" 12px \""+f+"\"").catch(()=>{})))).then(()=>document.fonts.load("italic 400 12px \""+SANS+"\"").catch(()=>{})):Promise.resolve(); ready.then(()=>loadPhoto(render)); window.__menuState=()=>ST; })();