def addWatermark(self): '''Create a Draft watermark layer. This was taken from: http://wiki.scribus.net/canvas/Adding_%27DRAFT%27_to_a_document''' L = len(self.watermark) # The length of the word # will determine the font size scribus.defineColor("gray", 11, 11, 11, 11) # Set your own color here u = scribus.getUnit() # Get the units of the document al = scribus.getActiveLayer() # Identify the working layer scribus.setUnit( scribus.UNIT_MILLIMETERS) # Set the document units to mm, (w, h) = scribus.getPageSize() # needed to set the text box size scribus.createLayer("c") scribus.setActiveLayer("c") T = scribus.createText(w / 6, 6 * h / 10, h, w / 2) # Create the text box scribus.setText(self.watermark, T) # Insert the text scribus.setTextColor("gray", T) # Set the color of the text scribus.setFontSize( (w / 210) * (180 - 10 * L), T) # Set the font size according to length and width scribus.rotateObject(45, T) # Turn it round antclockwise 45 degrees scribus.setUnit(u) # return to original document units # FIXME: It would be nice if we could move the watermark box down to the lowest layer so # that it is under all the page text. Have not found a method to do this. For now we just # plop the watermark on top of everything else. scribus.setActiveLayer(al) # return to the original active layer
def addWatermark (self) : '''Create a Draft watermark layer. This was taken from: http://wiki.scribus.net/canvas/Adding_%27DRAFT%27_to_a_document''' L = len(self.watermark) # The length of the word # will determine the font size scribus.defineColor("gray", 11, 11, 11, 11) # Set your own color here u = scribus.getUnit() # Get the units of the document al = scribus.getActiveLayer() # Identify the working layer scribus.setUnit(scribus.UNIT_MILLIMETERS) # Set the document units to mm, (w,h) = scribus.getPageSize() # needed to set the text box size scribus.createLayer("c") scribus.setActiveLayer("c") T = scribus.createText(w/6, 6*h/10 , h, w/2) # Create the text box scribus.setText(self.watermark, T) # Insert the text scribus.setTextColor("gray", T) # Set the color of the text scribus.setFontSize((w/210)*(180 - 10*L), T) # Set the font size according to length and width scribus.rotateObject(45, T) # Turn it round antclockwise 45 degrees scribus.setUnit(u) # return to original document units # FIXME: It would be nice if we could move the watermark box down to the lowest layer so # that it is under all the page text. Have not found a method to do this. For now we just # plop the watermark on top of everything else. scribus.setActiveLayer(al) # return to the original active layer
def main(argv): """Translate imported RGB colors to CMYK colors.""" ######################### # YOUR CODE GOES HERE # ######################### if scribus.haveDoc(): clrs = scribus.getColorNames() newname = "" for clr in clrs: if clr.find("From") == 0: cmyk = scribus.getColor(clr) c = cmyk[0] cd = c * 100 / 255 ca = "c" + str(cd) m = cmyk[1] md = m * 100 / 255 ma = "m" + str(md) y = cmyk[2] yd = y * 100 / 255 ya = "y" + str(yd) k = cmyk[3] kd = k * 100 / 255 ka = "k" + str(kd) newname = ca + ma + ya + ka scribus.defineColor(newname, c, m, y, k) scribus.replaceColor(clr, newname) scribus.deleteColor(clr, newname)
def prepareDocument(): """creates the new document, sets up colors """ colorList = getColorsFromDocument() spotDict = getSpotColors() scribus.statusMessage("Preparing new document...") scribus.newDocument(scribus.PAPER_A4, (15,15, 20, 20), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.PAGE_1, 0, 1) scribus.setUnit(scribus.UNIT_MILLIMETERS) #delete existing colors cols = scribus.getColorNames() for col in cols: scribus.deleteColor(col, "None") #create our new colors for color in colorList: cname=color[0] c = int(color[1]) m = int(color[2]) y = int(color[3]) k = int(color[4]) scribus.defineColor(cname, c, m, y, k ) if spotDict.has_key(cname): scribus.setSpotColor(cname, spotDict[cname]) #get the pageTitle form user and store it in PageTitle global pageTitle pageTitle=scribus.valueDialog("ColorChart by Sebastian Stetter", "Please enter document title", "Scribus COLOR CHART") drawHeaderFooter(pageTitle)
def addLogo(x, y, isBlack): #square side a=5 #line line=0.01 #angle angle=15 #LightGrey scribus.defineColor("LightGrey",0,0,0,128) #DarkGrey scribus.defineColor("DarkGrey",0,0,0,192) # White cards colors squareColor1="Black" lineColor1="White" squareColor2="DarkGrey" lineColor2="White" squareColor3="LightGrey" lineColor3="White" titleColor="Black" # Black cards colors if isBlack==True: squareColor1="DarkGrey" lineColor1="DarkGrey" squareColor2="LightGrey" lineColor2="LightGrey" squareColor3="White" lineColor3="White" titleColor="White" square1=scribus.createRect(x, y+a/10, a, a) scribus.setLineWidth(1, square1) scribus.setFillColor(squareColor1, square1) scribus.setLineColor(lineColor1, square1) scribus.rotateObject(angle, square1) square2=scribus.createRect(x+a/2, y, a, a) scribus.setLineWidth(1, square2) scribus.setFillColor(squareColor2, square2) scribus.setLineColor(lineColor2, square2) square3=scribus.createRect(x+a, y, a, a) scribus.setLineWidth(1, square3) scribus.setFillColor(squareColor3, square3) scribus.setLineColor(lineColor3, square3) scribus.rotateObject(-angle, square3) title=scribus.createText(x+10,y+2, 50, 5) scribus.setFont("Arial Bold", title) scribus.setFontSize(8, title) scribus.insertText("Game of Filth", 0, title) scribus.setTextColor(titleColor, title) return
def addLogo(x, y, isBlack): #square side a=5 #line line=0.01 #angle angle=15 #LightGrey scribus.defineColor("LightGrey",0,0,0,128) #DarkGrey scribus.defineColor("DarkGrey",0,0,0,192) # White cards colors squareColor1="Black" lineColor1="White" squareColor2="DarkGrey" lineColor2="White" squareColor3="LightGrey" lineColor3="White" titleColor="Black" # Black cards colors if isBlack==True: squareColor1="DarkGrey" lineColor1="DarkGrey" squareColor2="LightGrey" lineColor2="LightGrey" squareColor3="White" lineColor3="White" titleColor="White" square1=scribus.createRect(x, y+a/10, a, a) scribus.setLineWidth(1, square1) scribus.setFillColor(squareColor1, square1) scribus.setLineColor(lineColor1, square1) scribus.rotateObject(angle, square1) square2=scribus.createRect(x+a/2, y, a, a) scribus.setLineWidth(1, square2) scribus.setFillColor(squareColor2, square2) scribus.setLineColor(lineColor2, square2) square3=scribus.createRect(x+a, y, a, a) scribus.setLineWidth(1, square3) scribus.setFillColor(squareColor3, square3) scribus.setLineColor(lineColor3, square3) scribus.rotateObject(-angle, square3) title=scribus.createText(x+10,y+2, 50, 5) scribus.setFont("Arial Bold", title) scribus.setFontSize(8, title) scribus.insertText("Cards Against Humanity", 0, title) scribus.setTextColor(titleColor, title) return
def main(): if not scribus.haveDoc(): return for color_name in scribus.getColorNames(): if not color_name.startswith(('FromSVG', 'FromPDF')): continue c, m, y, k = scribus.getColor(color_name) cmyk_name = color_name[0:8] cmyk_name += f"{c*100//255:02x}{m*100//255:02x}{y*100//255:02x}{k*100//255:02x}" scribus.defineColor(cmyk_name, c, m, y, k) scribus.deleteColor(color_name, cmyk_name)
def importParametres(filename, idxPro): """check if colors exists and import""" log("importParametres: "+filename+"\n") colordict=getColorDict() colorlist=getColorsFromCsv(filename, idxPro) if idxPro==1: for color in colorlist: name=color[0] c=color[1] m=color[2] y=color[3] k=color[4] #while colordict.has_key(name): name = PREFIX+name# check if color already exists - then add PREFIX to name scribus.defineColor(name, c, m, y, k) return len(colorlist)
def importColors(colorlist): """check if colors exists an import""" colordict=getColorDict() scribus.statusMessage("Defining new colors...") scribus.progressTotal(len(colorlist)) i=0 for color in colorlist: name=color[0] c=color[1] m=color[2] y=color[3] k=color[4] while colordict.has_key(name):# check if color already exists - then add PREFIX to name name = PREFIX+name scribus.defineColor(name, c, m, y, k) i=i+1 scribus.progressSet(i)
def simpleGradient(my_parameters): '''Applies a simple (character by character) gradient to a TextFrame object''' try: TextFrame_object = my_parameters[0] CMYKstart = my_parameters[1] CMYKend = my_parameters[2] object_length = scribus.getTextLength(TextFrame_object) for i in range(0, object_length): scribus.selectText(i, 1, TextFrame_object) color = CMYKgradientPoint(CMYKstart, CMYKend, object_length, i) try: getColor(str(color)) except: scribus.defineColor(str(color), color[0], color[1], color[2], color[3]) scribus.setTextColor(str(color), TextFrame_object) except: print error_message_gradient_simple scribus.messageBox(TITLE, error_message_gradient_simple, scribus.ICON_WARNING)
def openScrb(self): paraStyles = scribus.getParagraphStyles() charStyles = scribus.getCharStyles() logger.debug("paraStyles: %s\ncharStyles:%s", str(paraStyles), str(charStyles)) self.parseParams() scribus.defineColor("ADFC_Yellow_", 0, 153, 255, 0) # scribus.defineColor("ADFC_Blue_", 230, 153, 26, 77) WD2_Y_ = { "name": "WD2_Y_", "font": "Wingdings 2 Regular", "fillcolor": "ADFC_Yellow_" } styles.cstyles["WD2_Y_"] = WD2_Y_ styles.checkPStyleExi("MD_P_REGULAR") styles.checkPStyleExi("MD_P_BLOCK") styles.checkCStyleExi("MD_C_REGULAR") styles.checkCStyleExi("MD_C_BOLD") styles.checkCStyleExi("WD2_Y_") styles.checkCStyleExi("MD_C_TOC")
#!/usr/bin/python # -*- coding: utf-8 -*- import sys import random import scribus # page size in inch (letter) pageX = 8.5 pageY = 11.0 lineY = 0.4125 spaceY = 0.1875 scribus.newDocument((pageX, pageY), (0.0, 0.0, 0.0, 0.0), scribus.PORTRAIT, 1, scribus.UNIT_INCHES, scribus.PAGE_1, 0, 1) scribus.defineColor("lightgray",21,21,21,21) scribus.defineColor("gray",51,51,51,51) scribus.defineColor("darkgray",91,91,91,91) l = scribus.createLine(1.0,0.0,1.0,11) scribus.setLineColor("gray", l) l = scribus.createLine(1.05,0.0,1.05,11) scribus.setLineColor("gray", l) for x in range(0,19): l = scribus.createLine(0.0,lineY-spaceY,8.5,lineY-spaceY) scribus.setLineColor("gray", l) l = scribus.createLine(0.0,lineY,8.5,lineY) scribus.setLineColor("lightgray", l) scribus.setLineStyle(scribus.LINE_DOT,l)
pageX = 8.5 pageY = 11.0 maxX = 2.0 maxY = 12.0 offsetX = 0.3 offsetXX = 0.2 offsetY = 0.15 minResultA = 0 maxResultA = 14 minResultB = 1 maxResultB = 3 rx = [[0 for col in range(100)] for row in range(100)] ry = [[0 for col in range(100)] for row in range(100)] scribus.newDocument((pageX, pageY), (0.0, 0.0, 0.0, 0.0), scribus.PORTRAIT, 1, scribus.UNIT_INCHES, scribus.PAGE_1, 0, 1) scribus.defineColor("gray",21,21,21,21) for x in range(0,maxX): for y in range(0,maxY): q = scribus.createText((x*((pageX*0.9)/maxX))+offsetX, (y*(pageY/maxY))+offsetY, (pageX*0.9)/maxX, pageY/maxY) scribus.setFont('Arial Regular',q) scribus.setFontSize(48, q) if random.randint(0, 1) == 0: rx[x][y] = random.randint(minResultB, maxResultB) ry[x][y] = random.randint(minResultA, maxResultA) else: rx[x][y] = random.randint(minResultA, maxResultA) ry[x][y] = random.randint(minResultB, maxResultB) rxx = rx[x][y] ryy = ry[x][y] scribus.insertText('%(rxx)d + %(ryy)d =__' % locals(), 0, q)
# add the baseline grid (when it's not too close to a guide) baseline_start = 0 # in mm baseline = 14.4 # in pt multiplicator = 10000 baseline = int(baseline * 0.352777 * multiplicator) # 14.4 pt in mm #baseline = int(baseline * 0.351459 * multiplicator) # 14.4 pt in mm if baseline > 0 : guide_i = 0 guide_list = scribus.getHGuides() guide_list.append(page[1]) guide = guide_list[guide_i] guide_n = len(guide_list) if not 'Gray' in scribus.getColorNames() : scribus.defineColor('Gray', 10, 10, 10, 10) for item in range(baseline + baseline_start*multiplicator, int(page[1] * multiplicator + baseline_start*multiplicator), baseline) : # print item/multiplicator while guide_i < guide_n - 1 and item/multiplicator > guide + 0.15 : guide_i = guide_i + 1 guide = guide_list[guide_i] if item/multiplicator < guide - 0.15 : line = scribus.createLine(0, item/multiplicator , page[0], item/multiplicator) scribus.setLineColor('Gray', line) scribus.setLineWidth(0.6, line) # scribus.setLineStyle(scribus.LINE_DASHDOT, line) # add the page margins rectangle = scribus.createRect(margin[1], margin[0], (page[0] - margin[1] - margin[2]), (page[1] - margin[0] - margin[3])) scribus.setFillColor('none', rectangle)
''' Add gradient background to every pages of the document''' import scribus import random topMargin, leftMargin, rightMargin, bottomMargin = scribus.getPageMargins() pageWidth, pageHeight = scribus.getPageSize() printAreaWidth = pageWidth - leftMargin - rightMargin printAreaHeight = pageHeight - topMargin - bottomMargin xPos = 0 yPos = 0 pageNumber = scribus.pageCount() currentPage = 1 scribus.createLayer("background") while (currentPage <= pageNumber): scribus.gotoPage(currentPage) c = random.randint(0,150) m = random.randint(0,150) y = random.randint(0,150) k = random.randint(0,150) gradientType = random.randint(1,5) scribus.defineColor("color1", c, m, y, k) scribus.defineColor("color2", k, y, m, c) rect = scribus.createRect(xPos, yPos, pageWidth, pageHeight) scribus.setGradientFill(gradientType, "color1", 90, "color2", 90, rect) #scribus.setGradientFill(1, "Black", 90, "White", 90, rect) currentPage += 1