viric ([info]viric) wrote,
@ 2007-05-08 23:15:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Entry tags:programado

Mia unua programo en icon!
Mi faris mian unuan programon en icon.

Ĝi kreas ĉenojn por pstops, por printi en A4 librojn, kiujn mi volas en paĝoj A5. Mi printas laŭ ĝusta ordo (psbook, kaj poste pstops), tiel ke estas du paĝoj por ĉiu papera paĝo, kaj en libroligilejo mi tranĉas laŭ duono de A4, kaj ligas per spiralo.

Mi tamen volas fojfoje grandigon por profiti bone la A5-paĝon (ne estu tro da marĝenoj), kaj moveti la originalajn paĝon por centrigi ilin en la fina A5 paĝo. Jen tion faras mia programo:

$ ./psturn x1 y0.5 z1.2 l
4:0L@0.85(23.60cm,-0.48cm)+1L@0.85(23.60cm,14.37cm),\
2R@.85(-2.60cm,30.18cm)+3R@0.85(-2.60cm,15.33cm)

Mi tranĉis la rezulton per \. Do, ĝi fakte movas ĉiun paĝeton centimetron dekstren, 0.5cm malsupren, kaj ĉiun grandigas per faktoro 1.2. Krome, pretigas la rezulton por printilo, kiu printas duflanke kvazaŭ la paĝoj estas vertikalaj. La grandigo ne malcentrigas paĝetojn.

Nu, se iu konas ps2ps, eble komprenos kial al mi plaĉas tiu ĉi programo. :) Tiel mi vokas:
$ ps2ps `./psturn y0.5 z1.2 l` dosiero.ps dosiero2.ps



LA KODO:
link numbers

global offsetx, offsety, zoom, orientation

$define A4_W 21
$define A4_H 29.7

procedure showhelp()
    write("usage: psturn [ xMOVX ] [ yMOVY ] [ zZOOM ] [ l ]")
    return
end

procedure process_param(text)
    text ? {
        ptype := tab(2)
        case ptype of {
            "x" : offsetx := real(tab(0))
            "y" : offsety := real(tab(0))
            "z" : zoom := real(tab(0))
            "l" : orientation := "landscape"
            default : fail
        }
    }
    return
end

procedure process_params(argv)
    every text := !argv do
        if not process_param(text) then
            fail
    return
end

procedure defaults()
    offsetx := 0.0
    offsety := 0.0
    zoom := 1
    orientation := "portrait"
end

# Prints (Xcm,Ycm)
procedure stroffsets(x,y)
    ret := "("
    ret ||:= frn(x,0,2) || "cm,"
    ret ||:= frn(y,0,2) || "cm)"
    return ret
end

procedure pagefront(poffset)
    final_zoom := sqrt(2)/2 * zoom

    centeringx := (A4_H * final_zoom - A4_W)/2
    centeringy := - (A4_W * final_zoom - A4_W * sqrt(2)/2)/2
    final_x1 := A4_W + offsety + centeringx
    final_y1 := offsetx + centeringy
    final_x2 := A4_W + offsety + centeringx
    final_y2 := A4_H/2 + offsetx + centeringy

    # Get the zoom string with two digits after .
    strfzoom := frn(final_zoom, 0, 2)

    # First page
    #   NL@(Xcm,Ycm)
    ret := string(poffset) || "L@" || strfzoom
    ret ||:= stroffsets(final_x1, final_y1)

    # Second page
    #   +NL@(Xcm,Ycm)
    ret ||:= "+" || string(poffset+1) || "L@" || strfzoom
    ret ||:= stroffsets(final_x2, final_y2)

    return ret
end

procedure pageback(poffset)
    final_zoom := sqrt(2)/2 * zoom

    centeringx := (A4_H * final_zoom - A4_W)/2
    centeringy := - (A4_W * final_zoom - A4_W * sqrt(2)/2)/2
    final_x1 := - offsety - centeringx
    final_y1 := A4_H - offsetx - centeringy
    final_x2 := - offsety - centeringx
    final_y2 := A4_H/2 - offsetx - centeringy

    # Get the zoom string with two digits after .
    strfzoom := frn(final_zoom, 0, 2)

    # First page
    #   NL@(Xcm,Ycm)
    ret := string(poffset) || "R@" || strfzoom
    ret ||:= stroffsets(final_x1, final_y1)

    # Second page
    #   +NL@(Xcm,Ycm)
    ret ||:= "+" || string(poffset+1) || "R@" || strfzoom
    ret ||:= stroffsets(final_x2, final_y2)

    return ret
end

procedure main(argv)
    defaults()
    if not process_params(argv) then
    {
        showhelp()
        return -1
    }

    firstpair := pagefront(0)
    if (orientation == "portrait") then
        secondpair := pagefront(2)
    else
        secondpair := pageback(2)

    write("4:" || firstpair || "," || secondpair) 
end


(Post a new comment)


[info]chemoelectric
2007-05-08 09:55 pm UTC (link)
Nur por sciigi vin … vi povas skribi: write("4:", firstpair, ",", secondpair)

(Reply to this)(Thread)


[info]viric
2007-05-08 10:04 pm UTC (link)
Aha. Mi sciis, sed nevole ne aplikis.

Nu, unua provo. :)

(Reply to this)(Parent)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…