Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates for Brother QL-570 made from cups ppd file #202

Open
goldnchild opened this issue Dec 16, 2024 · 0 comments
Open

Templates for Brother QL-570 made from cups ppd file #202

goldnchild opened this issue Dec 16, 2024 · 0 comments

Comments

@goldnchild
Copy link

goldnchild commented Dec 16, 2024

Hi,

I wanted to use some DK-1203 labels with my QL-570 and unfortunately, there wasn't a template predefined for them.

No matter how I defined a custom size within glabels 3.4.1 (the version packaged for Ubuntu 20.04) it just wouldn't work. (And I tried over and over again getting a red flashing light on the QL-570).

Within the cupswrapper printer driver source codes PPD file from brother's website there's a few sizes given.
The file name is brother_ql570_printer_en.ppd

https://support.brother.com/g/b/downloadlist.aspx?c=eu_ot&lang=en&prod=lpql570euk&os=130#SelectLanguageType-593_0_1

Why not write a script to do this in lua, and copying just the relevant lines:

Here's my crap script:


function printt(t) for i,j in pairs(t) do print(i,j) end end


pd = {}
ia = {}

function processline(l)
local index
	if string.find(l,"*PaperDimension") then tab = pd end
	if string.find(l,"*ImageableArea") then tab = ia end
	m=string.gmatch(l,"(%d+)")
	x=m()
	y=m()
	index=x.."x"..y
	mstart,mend,mstr = string.find(l,":.*\"(.*)\"")
	tab[index]={}
	for x in string.gmatch(mstr,"([%d%.]+)") do
	  table.insert(tab[index],x)
	end
end

dk={}
dk["17x54"]="DK-1204 DK-11204"
dk["17x87"]="DK-1203 DK-11203"
dk["23x23"]="DK-1221 DK-11221"
dk["29x90"]="DK-1201 DK-11201"
dk["38x90"]="DK-1208 DK-11208"
dk["39x48"]="DK-1220 DK-11220"
dk["52x29"]="DK-1226 DK-11226"
dk["62x29"]="DK-1209 DK-11209"
dk["62x100"]="DK-1202 DK-11202"

dksort={} dktosize = {} for i,j in pairs(dk) do table.insert(dksort,j) dktosize[j]=i end table.sort(dksort) printt(dksort) for i,j in pairs(dksort) do print(j,dktosize[j]) end


function lines(str)
  local result = {}
  local line
  for line in str:gmatch '[^\n]+' do
    table.insert(result, line)
  end
  return result
end

ppdstr = 
[[*ImageableArea 17x54/17mm x 54mm(2/3" x 2-1/8"):		"4.32 8.4  43.92  144.24"
*ImageableArea 17x87/17mm x 87mm(2/3" x 3-7/16"):		"4.32 8.4  43.92  237.84"
*ImageableArea 23x23/23mm x 23mm(10/11" x 10/11"):		"4.32 8.4  60.96  56.88"
*ImageableArea 29x90/29mm x 90mm(1-1/7" x 3-1/2"):		"4.32 8.4  77.76  246.24"
*ImageableArea 38x90/38mm x 90mm(1-1/2" x 3-1/2"):		"4.32 8.4  103.44 246.24"
*ImageableArea 39x48/39mm x 48mm(1-1/2" x 1-8/9"):		"4.32 8.4  106.32 127.20"
*ImageableArea 52x29/52mm x 29mm(2" x 1-1/7"):			"4.32 8.4  143.04 73.44"
*ImageableArea 62x29/62mm x 29mm(2-3/7" x 1-1/7"):		"4.32 8.4  171.36 73.44"
*ImageableArea 62x100/62mm x 100mm(2-3/7" x 4"):		"4.32 8.4  171.36 274.56"
*PaperDimension 17x54/17mm x 54mm(2/3" x 2-1/8"):		"48.24  152.64"
*PaperDimension 17x87/17mm x 87mm(2/3" x 3-7/16"):		"48.24  246.24"
*PaperDimension 23x23/23mm x 23mm(10/11" x 10/11"):		"65.28  65.28"
*PaperDimension 29x90/29mm x 90mm(1-1/7" x 3-1/2"):		"82.08  254.64"
*PaperDimension 38x90/38mm x 90mm(1-1/2" x 3-1/2"):		"107.76 254.64"
*PaperDimension 39x48/39mm x 48mm(1-1/2" x 1-8/9"):		"110.64 135.60"
*PaperDimension 52x29/52mm x 29mm(2" x 1-1/7"):			"147.36 81.84"
*PaperDimension 62x29/62mm x 29mm(2-3/7" x 1-1/7"):		"175.68 81.84"
*PaperDimension 62x100/62mm x 100mm(2-3/7" x 4"):		"175.68 282.96"]]

ppdlines=lines(ppdstr)
for linekey,linevalue in pairs(ppdlines) do processline(linevalue) end

function opentag(tag) io.write("<"..tag.." ") end
function endtag() io.write(">") print() end
function endtagclose() io.write("/>") print() end
function closetag(tag) print("</"..tag..">") end
function attr(at,val) io.write(at.."=\""..val.."\" ") end
function tab(t) io.write(string.rep(" ",t)) end

function maketemplate()
opentag("Template")attr("brand","Brother")attr("part","Generated "..dk[index])attr("size","Other")attr("width",pd[index][1].."pt")attr("height",pd[index][2].."pt")attr("description",index)endtag()
tab(4)opentag("Label-rectangle")attr("id","0")attr("width",pd[index][1].."pt")attr("height",pd[index][2].."pt")attr("round","4pt")attr("x_waste","0")attr("y_waste","0")endtag()
tab(8)opentag("Markup-rect")attr("x1",ia[index][1].."pt")attr("y1",ia[index][2].."pt")attr("w",ia[index][3].."pt")attr("h",ia[index][4].."pt")endtagclose()
tab(8)opentag("Layout")attr("nx","1")attr("ny","1")attr("x0","0")attr("y0","0")attr("dx","0")attr("dy","0")endtagclose()
tab(4)closetag("Label-rectangle")
closetag("Template")
end

print([[<?xml version="1.0"?>
<Glabels-templates xmlns="http://glabels.org/xmlns/3.0/">
]])
for key,value in pairs(dksort) do
  index=dktosize[value]
  maketemplate()
end
print()
print("</Glabels-templates>")

and the output (putting this inside of a file in $HOME/.config/libglabels/templates/brother_generated.template)

<?xml version="1.0"?>
<Glabels-templates xmlns="http://glabels.org/xmlns/3.0/">


<Template brand="Brother" part="Generated DK-1201 DK-11201" size="Other" width="82.08pt" height="254.64pt" description="29x90" >
    <Label-rectangle id="0" width="82.08pt" height="254.64pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="77.76pt" h="246.24pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>
<Template brand="Brother" part="Generated DK-1202 DK-11202" size="Other" width="175.68pt" height="282.96pt" description="62x100" >
    <Label-rectangle id="0" width="175.68pt" height="282.96pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="171.36pt" h="274.56pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>
<Template brand="Brother" part="Generated DK-1203 DK-11203" size="Other" width="48.24pt" height="246.24pt" description="17x87" >
    <Label-rectangle id="0" width="48.24pt" height="246.24pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="43.92pt" h="237.84pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>
<Template brand="Brother" part="Generated DK-1204 DK-11204" size="Other" width="48.24pt" height="152.64pt" description="17x54" >
    <Label-rectangle id="0" width="48.24pt" height="152.64pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="43.92pt" h="144.24pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>
<Template brand="Brother" part="Generated DK-1208 DK-11208" size="Other" width="107.76pt" height="254.64pt" description="38x90" >
    <Label-rectangle id="0" width="107.76pt" height="254.64pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="103.44pt" h="246.24pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>
<Template brand="Brother" part="Generated DK-1209 DK-11209" size="Other" width="175.68pt" height="81.84pt" description="62x29" >
    <Label-rectangle id="0" width="175.68pt" height="81.84pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="171.36pt" h="73.44pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>
<Template brand="Brother" part="Generated DK-1220 DK-11220" size="Other" width="110.64pt" height="135.60pt" description="39x48" >
    <Label-rectangle id="0" width="110.64pt" height="135.60pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="106.32pt" h="127.20pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>
<Template brand="Brother" part="Generated DK-1221 DK-11221" size="Other" width="65.28pt" height="65.28pt" description="23x23" >
    <Label-rectangle id="0" width="65.28pt" height="65.28pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="60.96pt" h="56.88pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>
<Template brand="Brother" part="Generated DK-1226 DK-11226" size="Other" width="147.36pt" height="81.84pt" description="52x29" >
    <Label-rectangle id="0" width="147.36pt" height="81.84pt" round="4pt" x_waste="0" y_waste="0" >
        <Markup-rect x1="4.32pt" y1="8.4pt" w="143.04pt" h="73.44pt" />
        <Layout nx="1" ny="1" x0="0" y0="0" dx="0" dy="0" />
    </Label-rectangle>
</Template>

</Glabels-templates>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant