Creating Markers - another version

From Scribus Wiki
Revision as of 20:43, 2 November 2006 by KStania (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
This article is part of the Scripts series.

This script places

  • cutting-marks
  • registration-marks
  • a colour-bar
  • a text-field and
  • guides

within a given crop-distance from the page-border. The colour-bar is positioned vertically and scaled accoring to the page-size and the crop-distance. The markers are put an a larger white background to be visible on black dark images etc.

All markers are placed on a chooseable layer.

Tested with scribus 1.3.3.3.

This script is the "marker drawing engine" of Bleed, create markers and export a document to pdf.


#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" 

Dieses Skript zeichnet
* Beschnittmarken
* Passermarken
* einen Farbkeil
* ein Textfeld und
* Hilfslinien

Wird für die Größe des Beschnittrandes 0 eingegeben, 
dann werden nur die Hilfslinien gezeichnet.

##########################################

This script draws

* crop-marks
* passer-marks
* a colour bar
* a text field and
* guides

to the actual page

if the crop-area is 0  
then only guides are drawn.

Author: Konrad Stania

#############################################

LICENSE:

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

"""

import sys
from datetime import date


try:
    from scribus import *
except ImportError:
    print "This script only runs from within Scribus."
    sys.exit(1)
    
def main():
    #setRedraw(False) 
    

    fgcol = valueDialog("draw-marks.py", "Foreground color for marks (script stops when color not existing)\nVordergrundfarbe fuer Marken (Skript bricht ab, wenn Farbe nicht vorhanden):" ,"regcol")
    colval = getColor(fgcol)
    defineColor("bleed_export_white_323567654", 0, 0, 0, 0)
    bgcol = "bleed_export_white_323567654"
    #bgcol = valueDialog("draw-marks.py", "Background color for marks (script stops when color not existing)\nHintergrundfarbe fuer Marken (Skript bricht ab, wenn Farbe nicht vorhanden):" ,"White")
    #olval = getColor(bgcol)

    theOldLayer = getActiveLayer()

    MarkLayer = valueDialog("draw-marks.py", "Layer-Ebene:" ,"Marks")
    MarkLayerExist = 0
    for xLayer in getLayers():
      if xLayer == "Marks":
         MarkLayerExist = 1
 
    if MarkLayerExist == 0:
      createLayer(MarkLayer)


    setActiveLayer(MarkLayer)



    #olval = getColor(bgcol)
        
    userUnit = getUnit()
    setUnit(0)

    UnitFakt = 1
    bleedVal = 20
    UnitType = "pt"    
    
    
    UnitType = valueDialog("draw-marks.py", "Unit for crop - Masseinheit fuer die Randgroesse \nPunkt = pt, Millimeter = mm, Zentimeter = cm " ,"mm")
    
    if UnitType == "mm":
        UnitFakt = 1/25.4*72
        bleedVal = 10
    
    if UnitType == "cm":
        UnitFakt = 1/2.54*72
        bleedVal = 1
    
    if UnitType == "pt":
        UnitType = "pt"
        UnitFakt = 1
        bleedVal = 30

    bleedVal = float(valueDialog("draw-marks.py", "How large is crop\nGroesse des Beschnittrandes ["+ UnitType +"]:\nif 0 then only guides are inserted - wenn 0, dann werden nur Hilfslinien eingefuegt" ,'%5.3f'% bleedVal))
    
    
    #which marks can be "l", "r", "b" and defines whether left, right or both marks are printed
    whichMarks = valueDialog("draw-marks.py - Where - Wo?", "left-links: l, right-rechts: r, both-beide: b" ,"b")

    doCropMarks = int(valueDialog("draw-marks.py", "Cut Marks - Drucke Schnittmarken 1=yes-ja, 0=no-nein" ,"1"))
    doRegMarks = int(valueDialog("draw-marks.py", "Passer Marks - Drucke Passermarken 1=yes-ja, 0=no-nein" ,"1"))
    doColorSamples = int(valueDialog("draw-marks.py", "Colour bar - Drucke Farbbalken 1=yes-ja, 0=no-nein" ,"1"))
    doGuides = int(valueDialog("draw-marks.py", "Guides-Hilfslinien 1=yes-ja, 0=no-nein" ,"1"))

    jobname = valueDialog("bleed_and_export.py", "Helper Text - Hilfstext, wird in den Rand gedruckt" ,"Created by Scribus") 
    if len(jobname) > 0:
          doJobText = int("1")
    else:
          doJobText = int("0")


    resultFileName = ""
    seitennummer = currentPage() 
 
    # draw marks etc
    if bleedVal*UnitFakt > 0:

      if doColorSamples == 1:
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
      if doCropMarks == 1:
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
      if doJobText == 1:
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
      if doRegMarks == 1:
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)

    if doGuides ==1:
  
       pageX,pageY = getPageSize()

       setHGuides(getHGuides() +[bleedVal*UnitFakt] + [pageY-bleedVal*UnitFakt])
            

       if whichMarks == "l" or whichMarks =="b":
         setVGuides(getVGuides() + [bleedVal*UnitFakt])

       if whichMarks == "r" or whichMarks =="b":
         setVGuides(getVGuides() + [pageX - bleedVal*UnitFakt])


    if userUnit < 4: 
      setUnit(userUnit)
    else:
      setUnit(2)

    setActiveLayer(theOldLayer)

    #setRedraw(True) 
    

        
def PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType,seitennummer):
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
    
    shortresultFileName = resultFileName[-23:] + "  Page-Seite: " + '%(0)05i'% {"0":seitennummer} + "  Date-Datum: " +  date.today().strftime("%Y-%m-%d")
    pageX,pageY = getPageSize()
    textboxT = createText(bleedVal*UnitFakt+2, 1, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-10)
    setTextColor(fgcol,textboxT)
    setLineWidth(0,textboxT)
    setLineColor(bgcol,textboxT)
    setFillColor(bgcol,textboxT) 
    insertText(shortresultFileName, 0,textboxT ) 
    setFontSize(6, textboxT)
    textboxB1 = createText(bleedVal*UnitFakt+2, pageY-bleedVal*UnitFakt + 8, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-9)
    setTextColor(fgcol,textboxB1)
    setLineWidth(0,textboxB1)
    setLineColor(bgcol,textboxB1)
    setFillColor(bgcol,textboxB1) 
    insertText("Total: " + '%5.2f'% (pageX/UnitFakt)  + "x" + '%5.2f'% (pageY/UnitFakt)+"["+UnitType+"]" + ", Crop-Beschnitt:" + '%5.2f'% bleedVal+"["+UnitType+"]" + ", Prod.:" + '%5.2f'% (pageX/UnitFakt - 2 * bleedVal) + "x"+ '%5.2f'% (pageY/UnitFakt - 2 * bleedVal)+"["+UnitType+"]", 0,textboxB1 )
    setFontSize(6, textboxB1)
    setLineSpacing(8,textboxB1)
    textboxB2 = createText(pageX/2 + 10, pageY-bleedVal*UnitFakt + 8, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-9)
    setTextColor(fgcol,textboxB2)
    setLineWidth(0,textboxB2)
    setLineColor(bgcol,textboxB2)
    setFillColor(bgcol,textboxB2) 
    insertText(jobname , 0,textboxB2 )
    setFontSize(6, textboxB2)
    setLineSpacing(8,textboxB2)


    

def DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt):

    defineColor("bleed_export_cm100",255,255,  0,  0)
    defineColor("bleed_export_my100",  0,255,255,  0)
    defineColor("bleed_export_cy100",255,  0,255,  0)   
    
    defineColor("bleed_export_c_100",255,  0,  0,  0)
    defineColor("bleed_export_c__80",204,  0,  0,  0)
    defineColor("bleed_export_c__40",102,  0,  0,  0)    

    defineColor("bleed_export_m_100",  0,255,  0,  0)
    defineColor("bleed_export_m__80",  0,204,  0,  0)
    defineColor("bleed_export_m__40",  0,102,  0,  0)
    
    defineColor("bleed_export_y_100",  0,  0,255,  0)
    defineColor("bleed_export_y__80",  0,  0,204,  0)
    defineColor("bleed_export_y__40",  0,  0,102,  0)
    
    defineColor("bleed_export_k_100",  0,  0,  0,255)
    defineColor("bleed_export_k__80",  0,  0,  0,204)
    defineColor("bleed_export_k__40",  0,  0,  0,102)
    
    defineColor("bleed_export_cmy50",128,128,128,  0)
    
    pageX,pageY = getPageSize()
    boxw = bleedVal*UnitFakt - 10
    if boxw > 20:
      boxw = 20
    FontSize = boxw/4
    if FontSize < 2 :
      FontSize = 2 
    boxdist = 5
    boxh = ((pageY - 20 - bleedVal*UnitFakt*2 - 20)  /  16) - boxdist
    if boxh > boxw:
      boxh = boxw 
    upperLeftx = pageX - boxw
    upperLefty = bleedVal*UnitFakt + 5
    gruppenListe = list()
    for Farbe in ["bleed_export_cm100","bleed_export_my100","bleed_export_cy100","bleed_export_c_100","bleed_export_c__80","bleed_export_c__40","bleed_export_m_100","bleed_export_m__80","bleed_export_m__40","bleed_export_y_100","bleed_export_y__80","bleed_export_y__40","bleed_export_k_100","bleed_export_k__80","bleed_export_k__40","bleed_export_cmy50"]:
       
       if upperLefty > pageY/2 - (FontSize * 1.5 + boxh + + 7 + 15):
         if upperLefty < pageY/2 - 15:
            upperLefty = pageY/2 + 20
       
       
       tbox = createText(upperLeftx, upperLefty, boxw, FontSize * 4)
       insertText(Farbe[len(Farbe)-5:len(Farbe)] , 0, tbox)
       setFontSize(FontSize, tbox)
       setLineSpacing(FontSize, tbox)
       setTextColor("regcol",tbox)
       setLineWidth(0, tbox)
       setLineColor(bgcol, tbox)
       setFillColor(bgcol, tbox)
       
       upperLefty = upperLefty + FontSize * 1.8

       cbox = createRect(upperLeftx, upperLefty, boxw, boxh)
       setLineWidth(0, cbox)
       setLineColor(Farbe, cbox)
       setFillColor(Farbe, cbox)       
       
       upperLefty = upperLefty + boxh + 7
       
       gruppenListe.append(cbox)
       gruppenListe.append(tbox)
       
    
    groupObjects(gruppenListe)
     
def DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks):
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
    pageX,pageY = getPageSize()
    # line widths unit pt
    lwb = 3.0
    lwf = 0.25

    if whichMarks == "l" or whichMarks == "b":
       # top left:
       b01 = createLine(bleedVal*UnitFakt, bleedVal*UnitFakt - 9,  bleedVal*UnitFakt, 0)
       b02 = createLine(0,  bleedVal*UnitFakt, bleedVal*UnitFakt -9 , bleedVal*UnitFakt)
       setLineWidth(lwb, b01)
       setLineWidth(lwb, b02)
       setLineColor(bgcol,b01)
       setLineColor(bgcol,b02)
       f01 = createLine(bleedVal*UnitFakt, bleedVal*UnitFakt - 9,  bleedVal*UnitFakt, 0)
       f02 = createLine(0,  bleedVal*UnitFakt, bleedVal*UnitFakt -9 , bleedVal*UnitFakt)
       setLineWidth(lwf, f01)
       setLineWidth(lwf, f02)
       setLineColor(fgcol,f01)
       setLineColor(fgcol,f02)

       # bottom left:
       b05 = createLine(bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,  bleedVal*UnitFakt ,pageY)
       b06 = createLine(0,pageY-bleedVal*UnitFakt,  bleedVal*UnitFakt -9 ,pageY-bleedVal*UnitFakt)
       setLineWidth(lwb, b05)
       setLineWidth(lwb, b06)
       setLineColor(bgcol,b05)
       setLineColor(bgcol,b06)
       f05 = createLine(bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,  bleedVal*UnitFakt ,pageY)
       f06 = createLine(0,pageY-bleedVal*UnitFakt,  bleedVal*UnitFakt -9 ,pageY-bleedVal*UnitFakt)
       setLineWidth(lwf, f05)
       setLineWidth(lwf, f06)
       setLineColor(fgcol,f05)
       setLineColor(fgcol,f06)

    if whichMarks == "r" or whichMarks == "b":
       # top right:
       b03 = createLine(pageX - bleedVal*UnitFakt + 9, bleedVal*UnitFakt,  pageX ,bleedVal*UnitFakt)
       b04 = createLine(pageX - bleedVal*UnitFakt,0,  pageX-bleedVal*UnitFakt,bleedVal*UnitFakt - 9)
       setLineWidth(lwb, b03)
       setLineWidth(lwb, b04)
       setLineColor(bgcol,b03)
       setLineColor(bgcol,b04)
       f03 = createLine(pageX - bleedVal*UnitFakt + 9, bleedVal*UnitFakt,  pageX ,bleedVal*UnitFakt)
       f04 = createLine(pageX - bleedVal*UnitFakt,0,  pageX-bleedVal*UnitFakt,bleedVal*UnitFakt - 9)
       setLineWidth(lwf, f03)
       setLineWidth(lwf, f04)
       setLineColor(fgcol,f03)
       setLineColor(fgcol,f04)

       # bottom rigth:
       b07 = createLine(pageX-bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,   pageX-bleedVal*UnitFakt,pageY)
       b08 = createLine(pageX,pageY-bleedVal*UnitFakt, pageX-bleedVal*UnitFakt + 9 ,pageY-bleedVal*UnitFakt)
       setLineWidth(lwb, b07)
       setLineWidth(lwb, b08)
       setLineColor(bgcol,b07)
       setLineColor(bgcol,b08)
       f07 = createLine(pageX-bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,   pageX-bleedVal*UnitFakt,pageY)
       f08 = createLine(pageX,pageY-bleedVal*UnitFakt, pageX-bleedVal*UnitFakt + 9 ,pageY-bleedVal*UnitFakt)
       setLineWidth(lwf, f07)
       setLineWidth(lwf, f08)
       setLineColor(fgcol,f07)
       setLineColor(fgcol,f08)


    
def DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks):

    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
    pageX,pageY = getPageSize()
    
    if whichMarks == "l" or whichMarks == "b":
       # left mark:
       DrawOneReg(bleedVal*UnitFakt-12.5,pageY/2,bgcol,fgcol)

    if whichMarks == "r" or whichMarks == "b":    
       # rigth mark:
       DrawOneReg(pageX-bleedVal*UnitFakt+12.5,pageY/2,bgcol,fgcol)

    # top mark:
    DrawOneReg(pageX/2,bleedVal*UnitFakt-12.5,bgcol,fgcol)
    # bottom mark:
    DrawOneReg(pageX/2,pageY-bleedVal*UnitFakt+12.5,bgcol,fgcol)

    
def DrawOneReg(centerX,centerY,bgcol,fgcol):
    # Diese Funktion muss in der Einheit Punkt aufgerufen werden
    outercircle = createEllipse(centerX-7.5,centerY-7.5 , 15, 15)
    middlecircle = createEllipse(centerX-5.5,centerY-5.5 , 11, 11)
    innercircle =  createEllipse(centerX-2.5,centerY-2.5 , 5, 5)
    lin01 = createLine(centerX-7.5, centerY,  centerX-2.5, centerY)
    lin02 = createLine(centerX+2.5, centerY,  centerX+7.5, centerY)
    lin03 = createLine(centerX, centerY-7.5,  centerX, centerY-2.5)
    lin04 = createLine(centerX, centerY+7.5,  centerX, centerY+2.5)

    lin05 = createLine(centerX-2.5, centerY,  centerX+2.5, centerY)
    lin06 = createLine(centerX, centerY-2.5,  centerX, centerY+2.5)
    
    # line widths in Poinzs
    lwb = 3.0
    lwf = 0.25
    
    setLineWidth(0,outercircle)
    setLineColor(bgcol,outercircle)
    setFillColor(bgcol,outercircle) 
    setLineWidth(lwf,middlecircle)
    setLineColor(fgcol,middlecircle)
    setFillColor(bgcol,middlecircle)
    setLineWidth(lwf,innercircle)
    setLineColor(fgcol,innercircle)
    setFillColor(fgcol,innercircle)
    setLineWidth(lwf,lin01)
    setLineWidth(lwf,lin02)
    setLineWidth(lwf,lin03)
    setLineWidth(lwf,lin04)
    setLineWidth(lwf,lin05)
    setLineWidth(lwf,lin06)
    setLineColor(fgcol,lin01)
    setLineColor(fgcol,lin02)
    setLineColor(fgcol,lin03)
    setLineColor(fgcol,lin04)
    setLineColor(bgcol,lin05)
    setLineColor(bgcol,lin06)

    
if __name__ == '__main__':
    if haveDoc():
        main()
    else:
        messageBox("draw-marks.py", "Diese Script benoetigt ein offenes Dokument.", ICON_INFORMATION)