Subversion Repositories Scribus

Rev

Rev 11879 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11780 cbradney 1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
 
4
"""
5
 
6
Diese Skript exportiert ein Dokument mit Beschnittrand samt Marken als PDF.
7
Hierzu ist wie folgt vorzugehen:
8
 
9
0) Ihr Dokument muß eine minimale Ablagefläche oberhalb, links und rechts von 20 pt und
10
   einen minimalen vertikalen Abstand zwischen den Seiten von 40 pt aufweisen
11
   (siehe Datei->Dokument einrichten->Anzeige). Das Script ist nur für Dokumente getestet,
12
   bei denen alle Seiten gleich groß sind!
13
 
11879 christoph 14
1) Speichern Sie Ihr Dokument.
11780 cbradney 15
 
11879 christoph 16
2) Starten Sie dieses Skript.
11780 cbradney 17
 
11879 christoph 18
3) Zuerst werden Sie nach Einheit und Größe des Beschnittrandes
11780 cbradney 19
   sowie die Farbnamen gefragt. Die Größe des Beschnittrandes wird automatisch verkleinert, wenn dieser
11879 christoph 20
   größer als der halbe vertikale Abstand zwischen den Seiten ist.
11780 cbradney 21
 
11879 christoph 22
4) Dann werden Sie nach dem Namen eines Verzeichnisses gefragt, in dem je ein Scribus-Dokument
23
   für linke und rechte Seiten abgelegt und die gedruckten Seiten abgelegt werden.
11780 cbradney 24
 
11879 christoph 25
5) Wählen Sie die Optioen für die Beschnittmarken und die Beschriftung aus.
11780 cbradney 26
 
27
 
11879 christoph 28
Sie erhalten nun für jede Seite eine PDF-Datei mit Beschnittrand und, falls gewählt, Schnittmarken, Passermarken und Hilfstext sowie einen Dateinamen aufgedruckt. Außerdem werden drei Scribus-Dateien angelegt.
11780 cbradney 29
 
11879 christoph 30
Autor: Konrad Stania mit Ergänzungen durch Gregory Pittman und Petr Vanek
11780 cbradney 31
 
32
##########################################
33
 
34
This script exports a document with 20 pt bleed and crop-marks as PDF.
35
 
36
USAGE:
37
 
38
 
39
0) Make a document with min. 20 pt scratch space above and on the right of the page and 40 pt vertical distance
40
   between the pages. The script is tested only for documents in which every page the same size.
41
 
11879 christoph 42
1) Save your document
11780 cbradney 43
 
11879 christoph 44
2) Start the script.
11780 cbradney 45
 
11879 christoph 46
3) Enter the unit and size of the bleed, the color names for the marks and text.
11780 cbradney 47
  The bleed will be automatically reduced if it's larger then the half vertical distance between the pages.
48
 
11879 christoph 49
4) Choose a directory where the tempory files and the output is stored.
11780 cbradney 50
 
11879 christoph 51
5) Choose whether you like to have marks and/or text.
11780 cbradney 52
 
11879 christoph 53
Execution of the script will result in one pdf for each page and three Scribus-files
11780 cbradney 54
 
11879 christoph 55
Author: Konrad Stania, with additions by Gregory Pittman and Petr Vanek
11780 cbradney 56
 
57
#############################################
58
 
59
LICENSE:
60
 
61
This program is free software; you can redistribute it and/or modify
62
it under the terms of the GNU General Public License as published by
63
the Free Software Foundation; either version 2 of the License, or
64
(at your option) any later version.
65
 
66
This program is distributed in the hope that it will be useful,
67
but WITHOUT ANY WARRANTY; without even the implied warranty of
68
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
69
GNU General Public License for more details.
70
 
71
You should have received a copy of the GNU General Public License
72
along with this program; if not, write to the Free Software
73
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
74
"""
75
 
76
# Craig Bradney, Scribus Team
11879 christoph 77
# 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826 and improved later on by Gregory Pittman and Petr Vanek.
78
# script is GPLd
11780 cbradney 79
 
80
import sys
81
from xml.dom import minidom
82
from datetime import date
83
import random
84
import os
85
 
86
try:
87
    from scribus import *
88
except ImportError:
89
    print "This script only runs from within Scribus."
90
    sys.exit(1)
91
 
92
def main():
93
    #setRedraw(False) 
94
 
95
    #the xml-interpretation with expat does not like some chars. We will have to substitute them and 
96
    #change this back before going to interpret the new files with scribus
97
    #Append this list, if you encounter an expat-error concerning xml with wrong chars
98
    #We have to decide if you are using it on Win or Linux
99
 
100
    charsToChangeWin1333 = ["","","","","","","", ""]
101
    charsToChangeLin1333 = ["\x1a","\x1b","\x1c","\x1d","\x1e","\x18","\x04", "\x05"]
11837 subik 102
    # petr vanek - lin chars are now the same as win ones
103
 
104
    ##charsToChangeLin1333 = ["UnSinnx"]
105
    #if os.name == "posix":
106
      #defaultSystemVersion = "lin1333"
107
    #else:
108
      #defaultSystemVersion = "win1333"
11780 cbradney 109
 
11837 subik 110
    #SystemVersion = valueDialog("Bleed and Marks - OS and Scribus Version - Betriebssystem und Scribus-Version:", "OS and Scribus Version: win1333 lin1333" ,defaultSystemVersion)
11780 cbradney 111
 
11837 subik 112
    #if SystemVersion == "lin1333":
113
      #charsToChange = charsToChangeLin1333
114
    #else:
115
      #charsToChange = charsToChangeWin1333
116
      #SystemVersion = "win1333"
11780 cbradney 117
 
11837 subik 118
    charsToChange = charsToChangeWin1333
119
 
11879 christoph 120
    fgcol = valueDialog("Bleed and Marks", "Foreground Color for Marks (The script will create the color if it doesn't exist)\nVordergrundfarbe für Marken (Das Skript erstellt die Farbe, wenn sie nicht vorhanden ist):" ,"regcol")
11837 subik 121
    if fgcol == '':
122
        return
123
    try:
124
        colval = getColor(fgcol)
125
    except NotFoundError:
126
        defineColor(fgcol, 0, 0, 0, 255)
127
        colval = getColor(fgcol)
128
 
11780 cbradney 129
    defineColor("bleed_export_white_323567654", 0, 0, 0, 0)
130
    bgcol = "bleed_export_white_323567654"
131
    #bgcol = valueDialog("Bleed and Marks", "Background color for marks (script stops if color doesn't exist)\nHintergrundfarbe für Marken (Skript bricht ab, wenn Farbe nicht vorhanden):" ,"White")
132
    #olval = getColor(bgcol)
11837 subik 133
 
11780 cbradney 134
    userUnit = getUnit()
135
    setUnit(0)
136
 
137
    #deselectAll()
138
 
11879 christoph 139
    baseDirName = fileDialog("Bleed and Marks - Output Directory - Ausgabeverzeichnis", "*","./" ,False, False, True)
11780 cbradney 140
 
141
    baseFileName = baseDirName + "scribus_print"
142
    exportType = "pdf"
143
    UnitFakt = 1
144
    bleedVal = 20
145
    UnitType = "pt"    
11837 subik 146
 
11879 christoph 147
    UnitType = valueDialog("Bleed and Marks", "Unit for Bleed - Maßeinheit für die Randgröße \npt, mm, cm , mm")
11837 subik 148
 
11780 cbradney 149
    if UnitType == "mm":
150
        UnitFakt = 1/25.4*72
151
        bleedVal = int(20.0/72*2.54*10)
11837 subik 152
 
11780 cbradney 153
    if UnitType == "cm":
154
        UnitFakt = 1/2.54*72
155
        bleedVal = 0.1*int(20.0/72*2.54*10)
156
 
157
    if UnitType == "pt":
158
        UnitType = "pt"
159
        UnitFakt = 1
160
        bleedVal = 20
161
 
11879 christoph 162
    bleedVal = float(valueDialog("Bleed and Marks", "Size of Bleed, automatically limited to half of vertical gap between pages["+ UnitType +"]\nGröße des Beschnittrandes, automatisch beschränkt auf den halben vertikalen Abstand zwischen den Seiten ["+ UnitType +"]:" ,'%5.3f'% bleedVal))
11780 cbradney 163
 
164
 
11879 christoph 165
    TypeOfPages = valueDialog("Bleed and Marks - Pagetype - Seitenart", "Double first right - Doppelseite, erste rechts = dr,\nDouble first left - Doppelseite, erste links = dl,\nSingle pages - Einzelne Seiten = s" ,"dr")
11780 cbradney 166
    #which marks can be "l", "r", "b" and defines whether left, right or both marks are printed
167
    whichMarks = "b"
168
 
169
    if TypeOfPages <> "errfind":
170
 
171
        doCropMarks = int(valueDialog("Bleed and Marks", "Print Crop Marks - Drucke Schnittmarken 1=Yes-Ja, 0=No-Nein" ,"1"))
11879 christoph 172
        doRegMarks = int(valueDialog("Bleed and Marks", "Print Registration Marks - Drucke Paßkreuze 1=Yes-Ja, 0=No-Nein" ,"1"))
11780 cbradney 173
        doColorSamples = int(valueDialog("Bleed and Marks", "Print color bar - Drucke Farbbalken 1=Yes-Ja, 0=No-Nein" ,"1"))
174
 
11879 christoph 175
        jobname = valueDialog("Bleed and Marks", "Info Text - Infotext" ,"Created by Scribus")
11780 cbradney 176
        if len(jobname) > 0:
177
          doJobText = int("1")
178
        else:
179
          doJobText = int("0")
180
 
181
    #preparing the file-environment
182
 
183
    tmpFileName = baseDirName + "tmp.sla"
184
    rightPageName = baseDirName + "rightpage.sla"
185
    leftPageName = baseDirName + "leftpage.sla"
186
    saveDocAs(tmpFileName)
11879 christoph 187
    messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11894 subik 188
    #closeDoc()
11879 christoph 189
    messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 190
 
191
    #Here we clean-up the xml documents from illegal characters
192
    #Here we replace \x1A \x1B \x1C etc. in the Document to prevent expat from crashing
193
    #these are stored in the list charsToChange
194
    inFile = open(tmpFileName,"r")
195
    richtig = inFile.read()
196
    inFile.close()
197
 
198
    # define an uniqe string to replace the bad chars
199
    charsToChangeMark = "__bleed_and_export_" + '%4.0f'% (10000+80000*random.random())
200
    while richtig.find(charsToChangeMark) > (-1) :
201
       charsToChangeMark = "__bleed_and_export_" + '%4.0f'% (10000+80000*random.random())
202
 
203
    # change all bad chars
204
    toChangeCounter = 1000
205
    for toChange in charsToChange:
206
        richtig = richtig.replace(toChange,charsToChangeMark +"_"+ '%4i'% toChangeCounter)
207
        toChangeCounter = toChangeCounter + 1
208
 
209
    # write the corrected tmp-file
210
    outFile = open(tmpFileName,"w")
211
    outFile.write(richtig)
212
    outFile.close()
213
 
214
    if TypeOfPages == "errfind":
215
      # this helps to find the illegal ones
216
      LineNumber = int(valueDialog("bleed_and_export.py", "Line-Zeile" ,"1"))
217
      #ColNumber = int(valueDialog("bleed_and_export.py", "Collumn-Spalte" ,"1"))
218
 
219
      inFile = open(tmpFileName,"r")
220
      for x in range(LineNumber):
221
        Zeile = inFile.readline()
222
 
223
      inFile.close()
224
      suspectList = "Dangerous chars: "
225
      Spalte = 0
226
 
227
      if SystemVersion == "win1333":
228
 
229
        for x in Zeile:
230
           if Zeile[Spalte:Spalte+3] == "&#x":
231
             suspect = Zeile[Spalte:Spalte+6]
232
             suspectList = suspectList + suspect[0:1+suspect.find(";")] + " "
233
 
234
           Spalte = Spalte + 1
235
 
236
 
237
        messageBox("Bleed and Marks", suspectList + "The following would be valid - Achtung, folgende wären gültig: &#x9, &#xa, &#xd" , ICON_INFORMATION)
238
 
239
      if SystemVersion == "lin1333":
240
        spalte = 0
241
        for x in Zeile:
242
           if ord(Zeile[Spalte]) < ord("\x1f"):
243
 
244
             suspect = " "'%x'% ord(Zeile[Spalte])
245
             suspectList = suspectList + suspect
246
 
247
           Spalte = Spalte + 1
248
 
249
 
250
        messageBox("Bleed and Marks", suspectList + "The following would be valid - Achtung, folgende wären gültig: 9, a, d"  , ICON_INFORMATION)
251
 
252
 
253
 
254
 
255
 
256
    if TypeOfPages == "s" or TypeOfPages =="dr" or TypeOfPages =="dl":
257
      #Here we make the xml-operations for left pages:
258
 
259
      xmldoc = minidom.parse(tmpFileName)
260
      theDocumentNode = xmldoc.getElementsByTagName('DOCUMENT')
261
      theDocumentNodeRef = theDocumentNode[0]
262
 
263
      thePageSetSetsNodeRef = theDocumentNodeRef.getElementsByTagName('PageSets')[0].getElementsByTagName('Set')
264
 
265
      for xRef in thePageSetSetsNodeRef:
266
 
267
          if float(xRef.attributes["GapBelow"].value) <= (2 * bleedVal*UnitFakt):
268
 
269
              bleedVal = float(xRef.attributes["GapBelow"].value) / UnitFakt / 2
270
 
271
 
272
      for xRef in thePageSetSetsNodeRef:
273
          xRef.attributes["GapBelow"].value = '%5.3f'%(float(xRef.attributes["GapBelow"].value) - 2 *bleedVal*UnitFakt)
274
 
275
      theDocumentNodeRef.attributes["PAGEHEIGHT"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
276
      theDocumentNodeRef.attributes["PAGEWIDTH"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
277
      theDocumentNodeRef.attributes["ScratchTop"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchTop"].value) - bleedVal*UnitFakt)
278
      theDocumentNodeRef.attributes["ScratchLeft"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchLeft"].value) - bleedVal*UnitFakt)
279
 
280
      thePageNodeRef = theDocumentNodeRef.getElementsByTagName('PAGE')
281
      for xRef in thePageNodeRef :
282
          xRef.attributes["PAGEHEIGHT"].value =   '%5.3f'%(float(xRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
283
          xRef.attributes["PAGEWIDTH"].value =   '%5.3f'%(float(xRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
284
 
285
      theMasterPageNodeRef = theDocumentNodeRef.getElementsByTagName('MASTERPAGE')
286
 
287
      for xRef in theMasterPageNodeRef :
288
          xRef.attributes["PAGEHEIGHT"].value = '%5.3f'%(float(xRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
289
          xRef.attributes["PAGEWIDTH"].value =  '%5.3f'%(float(xRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
290
          xRef.attributes["PAGEXPOS"].value =   '%5.3f'%(float(xRef.attributes["PAGEXPOS"].value)  -  bleedVal*UnitFakt)
291
          xRef.attributes["PAGEYPOS"].value =   '%5.3f'%(float(xRef.attributes["PAGEYPOS"].value) -  bleedVal*UnitFakt)
292
 
293
      outxml  = xmldoc.toxml()
294
 
295
      #put back the bad  chars
296
      toChangeCounter = 1000
297
      for toChange in charsToChange:
298
        outxml = outxml.replace(charsToChangeMark +"_" + '%4i'% toChangeCounter, toChange)
299
        toChangeCounter = toChangeCounter + 1
300
 
301
      outFile = open(leftPageName, 'w')
302
      outFile.write(outxml[outxml.find("<SCRIBUS"):len(outxml)])
303
      outFile.close()
304
      outxml = "n"
305
 
306
 
307
    if TypeOfPages =="dr" or TypeOfPages =="dl":
308
       #Here we make the xml-operations for right pages of double sides documents
309
 
310
      theDocumentNodeRef.attributes["ScratchLeft"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchLeft"].value) - 2 * bleedVal*UnitFakt)
311
 
312
      outxml  = xmldoc.toxml()
313
 
314
      #put back the illegal char
315
 
316
      toChangeCounter = 1000
317
      for toChange in charsToChange:
318
        outxml = outxml.replace(charsToChangeMark +"_" + '%4i'% toChangeCounter, toChange)
319
        toChangeCounter = toChangeCounter + 1
320
 
321
      outFile = open(rightPageName, 'w')
322
      outFile.write(outxml[outxml.find("<SCRIBUS"):len(outxml)])
323
      outFile.close()
324
      outxml = "n"
325
 
326
 
327
    #From here we do the drawing and exporting to pdf
328
 
329
    if TypeOfPages == "dr":
330
      ##and here we open it
331
 
332
      openDoc(rightPageName)
333
 
11879 christoph 334
      messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 335
 
336
      seitenanzahl = pageCount()
337
      for xcounter in range(seitenanzahl):
338
          seitennummer = xcounter + 1
339
          if seitennummer%2 > 0:  
340
             gotoPage(seitennummer)
341
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
342
             # draw marks etc
343
             if doColorSamples == 1:
344
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
345
             if doCropMarks == 1:
346
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
347
             if doJobText == 1:
348
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
349
             if doRegMarks == 1:
350
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
351
             # export one page
352
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
353
 
354
 
355
      saveDoc()
356
      closeDoc()
357
 
11879 christoph 358
      messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 359
 
360
      openDoc(leftPageName)
361
 
11879 christoph 362
      messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 363
 
364
      seitenanzahl = pageCount()
365
      for xcounter in range(seitenanzahl ):
366
          seitennummer = xcounter + 1
367
          if seitennummer%2 == 0:  
368
             gotoPage(seitennummer)
369
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
370
             # draw marks etc
371
             if doColorSamples == 1:
372
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
373
             if doCropMarks == 1:
374
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
375
             if doJobText == 1:
376
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
377
             if doRegMarks == 1:
378
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
379
             # export one page
380
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
381
 
382
 
383
      saveDoc()
384
      closeDoc()
385
      os.remove(tmpFileName)
386
 
387
 
388
    if TypeOfPages == "s":
389
 
390
    ##and here we open it
391
 
392
      openDoc(leftPageName)
393
 
11879 christoph 394
      messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 395
 
396
      seitenanzahl = pageCount()
397
 
398
      for xcounter in range(seitenanzahl):
399
          seitennummer = xcounter + 1
400
 
401
          gotoPage(seitennummer)
402
          resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
403
          # draw marks etc
404
          if doColorSamples == 1:
405
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
406
          if doCropMarks == 1:
407
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
408
          if doJobText == 1:
409
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
410
          if doRegMarks == 1:
411
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
412
 
413
             # export one page
414
          dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
415
 
416
 
417
      saveDoc()
418
      #closeDoc()
419
      os.remove(tmpFileName)
420
 
421
 
422
    if TypeOfPages == "dl":
423
 
424
 
425
      ##and here we open it
426
 
427
      openDoc(rightPageName)
428
 
11879 christoph 429
      messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 430
 
431
      seitenanzahl = pageCount()
432
      for xcounter in range(seitenanzahl ):
433
          seitennummer = xcounter + 1
434
          if seitennummer%2 == 0:  
435
             gotoPage(seitennummer)
436
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
437
             # draw marks etc
438
             if doColorSamples == 1:
439
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
440
             if doCropMarks == 1:
441
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
442
             if doJobText == 1:
443
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
444
             if doRegMarks == 1:
445
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
446
             # export one page
447
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
448
 
449
 
450
      saveDoc()
451
      closeDoc()
11879 christoph 452
      messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 453
      openDoc(leftPageName)
11879 christoph 454
      messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 455
 
456
      seitenanzahl = pageCount()
457
      for xcounter in range(seitenanzahl ):
458
          seitennummer = xcounter + 1
459
          if seitennummer%2 > 0:  
460
             gotoPage(seitennummer)
461
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
462
             # draw marks etc
463
             if doColorSamples == 1:
464
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
465
             if doCropMarks == 1:
466
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
467
             if doJobText == 1:
468
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
469
             if doRegMarks == 1:
470
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
471
             # export one page
472
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
473
 
474
      saveDoc()
475
      closeDoc()
476
 
11894 subik 477
    # OK, it's ugly, but it ensures the tmp files deletion
478
    try:
479
        os.remove(tmpFileName)
480
    except OSError:
481
        pass
482
    try:
483
        os.remove(rightPageName)
484
    except OSError:
485
        pass
486
    try:
487
        os.remove(leftPageName)
488
    except OSError:
489
        pass
11780 cbradney 490
 
11894 subik 491
    setUnit(userUnit)
492
    setRedraw(True)
493
 
494
 
11780 cbradney 495
def dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt):
496
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
497
    if exportType == "pdf":
498
      pdfExport =  PDFfile()
499
      pdfExport.bleedt = bleedVal*UnitFakt
500
      pdfExport.bleedb = bleedVal*UnitFakt
501
      pdfExport.bleedl = bleedVal*UnitFakt
502
      pdfExport.bleedr = bleedVal*UnitFakt
503
      pdfExport.info = resultFileName
504
      pdfExport.pages = [seitennummer]
505
      pdfExport.file = resultFileName
506
      pdfExport.save()
507
 
508
   # if exportType == "ps":
509
   #   psExport = Printer()
510
   #   psExport.file = resultFileName
511
   #   psExport.copies = 1
512
   #   psExport.pages = [seitennummer]
513
   #   psExport.printer = "File"
514
   #   psExport.print()
515
 
516
def PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType,seitennummer):
517
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
518
 
519
    shortresultFileName = resultFileName[-23:] + "  Page-Seite: " + '%(0)05i'% {"0":seitennummer} + "  Date-Datum: " +  date.today().strftime("%Y-%m-%d")
520
    pageX,pageY = getPageSize()
521
    textboxT = createText(bleedVal*UnitFakt+2, 1, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-10)
522
    setTextColor(fgcol,textboxT)
523
    setLineWidth(0,textboxT)
524
    setLineColor(bgcol,textboxT)
525
    setFillColor(bgcol,textboxT)
526
    insertText(shortresultFileName, 0,textboxT )
527
    setFontSize(6, textboxT)
528
    textboxB1 = createText(bleedVal*UnitFakt+2, pageY-bleedVal*UnitFakt + 8, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-9)
529
    setTextColor(fgcol,textboxB1)
530
    setLineWidth(0,textboxB1)
531
    setLineColor(bgcol,textboxB1)
532
    setFillColor(bgcol,textboxB1)
533
    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 )
534
    setFontSize(6, textboxB1)
535
    setLineSpacing(8,textboxB1)
536
    textboxB2 = createText(pageX/2 + 10, pageY-bleedVal*UnitFakt + 8, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-9)
537
    setTextColor(fgcol,textboxB2)
538
    setLineWidth(0,textboxB2)
539
    setLineColor(bgcol,textboxB2)
540
    setFillColor(bgcol,textboxB2)
541
    insertText(jobname , 0,textboxB2 )
542
    setFontSize(6, textboxB2)
543
    setLineSpacing(8,textboxB2)
544
 
545
 
546
 
547
 
548
def DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt):
549
 
550
    defineColor("bleed_export_c_100",255,  0,  0,  0)
551
    defineColor("bleed_export_c__80",204,  0,  0,  0)
552
    defineColor("bleed_export_c__40",102,  0,  0,  0)    
553
 
554
    defineColor("bleed_export_m_100",  0,255,  0,  0)
555
    defineColor("bleed_export_m__80",  0,204,  0,  0)
556
    defineColor("bleed_export_m__40",  0,102,  0,  0)
557
 
558
    defineColor("bleed_export_y_100",  0,  0,255,  0)
559
    defineColor("bleed_export_y__80",  0,  0,204,  0)
560
    defineColor("bleed_export_y__40",  0,  0,102,  0)
561
 
562
    defineColor("bleed_export_k_100",  0,  0,  0,255)
563
    defineColor("bleed_export_k__80",  0,  0,  0,204)
564
    defineColor("bleed_export_k__40",  0,  0,  0,102)
565
 
566
    defineColor("bleed_export_cmy50",128,128,128,  0)
567
 
568
    pageX,pageY = getPageSize()
569
    boxw = bleedVal*UnitFakt - 10
570
    if boxw > 20:
571
      boxw = 20
572
    FontSize = boxw/4
573
    if FontSize < 2 :
574
      FontSize = 2
575
    boxdist = 5
576
    boxh = ((pageY - 20 - bleedVal*UnitFakt*2 - 20)  /  13) - boxdist
577
    if boxh > boxw:
578
      boxh = boxw
579
    upperLeftx = pageX - boxw
580
    upperLefty = bleedVal*UnitFakt + 5
581
    gruppenListe = list()
582
    for Farbe in ["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"]:
583
 
584
       if upperLefty > pageY/2 - (FontSize * 1.5 + boxh + + 7 + 15):
585
         if upperLefty < pageY/2 - 15:
586
            upperLefty = pageY/2 + 20
587
 
588
 
589
       tbox = createText(upperLeftx, upperLefty, boxw, FontSize * 4)
590
       insertText(Farbe[len(Farbe)-5:len(Farbe)] , 0, tbox)
591
       setFontSize(FontSize, tbox)
592
       setLineSpacing(FontSize, tbox)
593
       setTextColor("regcol",tbox)
594
       setLineWidth(0, tbox)
595
       setLineColor(bgcol, tbox)
596
       setFillColor(bgcol, tbox)
597
 
598
       upperLefty = upperLefty + FontSize * 1.8
599
 
600
       cbox = createRect(upperLeftx, upperLefty, boxw, boxh)
601
       setLineWidth(0, cbox)
602
       setLineColor(Farbe, cbox)
603
       setFillColor(Farbe, cbox)      
604
 
605
       upperLefty = upperLefty + boxh + 7
606
 
607
       gruppenListe.append(cbox)
608
       gruppenListe.append(tbox)
609
 
610
 
611
    groupObjects(gruppenListe)
612
 
613
def DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks):
614
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
615
    pageX,pageY = getPageSize()
616
    # line widths unit pt
617
    lwb = 3.0
618
    lwf = 0.25
619
 
620
    if whichMarks == "l" or whichMarks == "b":
621
       # top left:
622
       b01 = createLine(bleedVal*UnitFakt, bleedVal*UnitFakt - 9,  bleedVal*UnitFakt, 0)
623
       b02 = createLine(0,  bleedVal*UnitFakt, bleedVal*UnitFakt -9 , bleedVal*UnitFakt)
624
       setLineWidth(lwb, b01)
625
       setLineWidth(lwb, b02)
626
       setLineColor(bgcol,b01)
627
       setLineColor(bgcol,b02)
628
       f01 = createLine(bleedVal*UnitFakt, bleedVal*UnitFakt - 9,  bleedVal*UnitFakt, 0)
629
       f02 = createLine(0,  bleedVal*UnitFakt, bleedVal*UnitFakt -9 , bleedVal*UnitFakt)
630
       setLineWidth(lwf, f01)
631
       setLineWidth(lwf, f02)
632
       setLineColor(fgcol,f01)
633
       setLineColor(fgcol,f02)
634
 
635
       # bottom left:
636
       b05 = createLine(bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,  bleedVal*UnitFakt ,pageY)
637
       b06 = createLine(0,pageY-bleedVal*UnitFakt,  bleedVal*UnitFakt -9 ,pageY-bleedVal*UnitFakt)
638
       setLineWidth(lwb, b05)
639
       setLineWidth(lwb, b06)
640
       setLineColor(bgcol,b05)
641
       setLineColor(bgcol,b06)
642
       f05 = createLine(bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,  bleedVal*UnitFakt ,pageY)
643
       f06 = createLine(0,pageY-bleedVal*UnitFakt,  bleedVal*UnitFakt -9 ,pageY-bleedVal*UnitFakt)
644
       setLineWidth(lwf, f05)
645
       setLineWidth(lwf, f06)
646
       setLineColor(fgcol,f05)
647
       setLineColor(fgcol,f06)
648
 
649
    if whichMarks == "r" or whichMarks == "b":
650
       # top right:
651
       b03 = createLine(pageX - bleedVal*UnitFakt + 9, bleedVal*UnitFakt,  pageX ,bleedVal*UnitFakt)
652
       b04 = createLine(pageX - bleedVal*UnitFakt,0,  pageX-bleedVal*UnitFakt,bleedVal*UnitFakt - 9)
653
       setLineWidth(lwb, b03)
654
       setLineWidth(lwb, b04)
655
       setLineColor(bgcol,b03)
656
       setLineColor(bgcol,b04)
657
       f03 = createLine(pageX - bleedVal*UnitFakt + 9, bleedVal*UnitFakt,  pageX ,bleedVal*UnitFakt)
658
       f04 = createLine(pageX - bleedVal*UnitFakt,0,  pageX-bleedVal*UnitFakt,bleedVal*UnitFakt - 9)
659
       setLineWidth(lwf, f03)
660
       setLineWidth(lwf, f04)
661
       setLineColor(fgcol,f03)
662
       setLineColor(fgcol,f04)
663
 
664
       # bottom rigth:
665
       b07 = createLine(pageX-bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,   pageX-bleedVal*UnitFakt,pageY)
666
       b08 = createLine(pageX,pageY-bleedVal*UnitFakt, pageX-bleedVal*UnitFakt + 9 ,pageY-bleedVal*UnitFakt)
667
       setLineWidth(lwb, b07)
668
       setLineWidth(lwb, b08)
669
       setLineColor(bgcol,b07)
670
       setLineColor(bgcol,b08)
671
       f07 = createLine(pageX-bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,   pageX-bleedVal*UnitFakt,pageY)
672
       f08 = createLine(pageX,pageY-bleedVal*UnitFakt, pageX-bleedVal*UnitFakt + 9 ,pageY-bleedVal*UnitFakt)
673
       setLineWidth(lwf, f07)
674
       setLineWidth(lwf, f08)
675
       setLineColor(fgcol,f07)
676
       setLineColor(fgcol,f08)
677
 
678
 
679
 
680
def DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks):
681
 
682
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
683
    pageX,pageY = getPageSize()
684
 
685
    if whichMarks == "l" or whichMarks == "b":
686
       # left mark:
687
       DrawOneReg(bleedVal*UnitFakt-12.5,pageY/2,bgcol,fgcol)
688
 
689
    if whichMarks == "r" or whichMarks == "b":    
690
       # rigth mark:
691
       DrawOneReg(pageX-bleedVal*UnitFakt+12.5,pageY/2,bgcol,fgcol)
692
 
693
    # top mark:
694
    DrawOneReg(pageX/2,bleedVal*UnitFakt-12.5,bgcol,fgcol)
695
    # bottom mark:
696
    DrawOneReg(pageX/2,pageY-bleedVal*UnitFakt+12.5,bgcol,fgcol)
697
 
698
 
699
def DrawOneReg(centerX,centerY,bgcol,fgcol):
700
    # Diese Funktion muss in der Einheit Punkt aufgerufen werden
701
    outercircle = createEllipse(centerX-7.5,centerY-7.5 , 15, 15)
702
    middlecircle = createEllipse(centerX-5.5,centerY-5.5 , 11, 11)
703
    innercircle =  createEllipse(centerX-2.5,centerY-2.5 , 5, 5)
704
    lin01 = createLine(centerX-7.5, centerY,  centerX-2.5, centerY)
705
    lin02 = createLine(centerX+2.5, centerY,  centerX+7.5, centerY)
706
    lin03 = createLine(centerX, centerY-7.5,  centerX, centerY-2.5)
707
    lin04 = createLine(centerX, centerY+7.5,  centerX, centerY+2.5)
708
 
709
    lin05 = createLine(centerX-2.5, centerY,  centerX+2.5, centerY)
710
    lin06 = createLine(centerX, centerY-2.5,  centerX, centerY+2.5)
711
 
712
    # line widths in Poinzs
713
    lwb = 3.0
714
    lwf = 0.25
715
 
716
    setLineWidth(0,outercircle)
717
    setLineColor(bgcol,outercircle)
718
    setFillColor(bgcol,outercircle)
719
    setLineWidth(lwf,middlecircle)
720
    setLineColor(fgcol,middlecircle)
721
    setFillColor(bgcol,middlecircle)
722
    setLineWidth(lwf,innercircle)
723
    setLineColor(fgcol,innercircle)
724
    setFillColor(fgcol,innercircle)
725
    setLineWidth(lwf,lin01)
726
    setLineWidth(lwf,lin02)
727
    setLineWidth(lwf,lin03)
728
    setLineWidth(lwf,lin04)
729
    setLineWidth(lwf,lin05)
730
    setLineWidth(lwf,lin06)
731
    setLineColor(fgcol,lin01)
732
    setLineColor(fgcol,lin02)
733
    setLineColor(fgcol,lin03)
734
    setLineColor(fgcol,lin04)
735
    setLineColor(bgcol,lin05)
736
    setLineColor(bgcol,lin06)
737
 
738
 
739
if __name__ == '__main__':
740
    if haveDoc():
741
        main()
742
    else:
11879 christoph 743
        messageBox("Bleed and Marks", "There must be an open document." "Es muß ein Dokument geöffnet sein.", ICON_INFORMATION)