示例#1
0
    def getSnapshot(self, width, height, offsetX, offsetY, snapline):
        """
	    Test
	    """
        rich = "<div class='richcolumn'>"
        articles = self.getArticle()
        theWordage = ""
        for article in articles:
            theWordage = article.getWordage()
            # get rid of tags
        theVerbage = re.sub("<.>", "", theWordage)
        theVerbage2 = re.sub("<\/.>", "", theVerbage)
        wordlen = len(theVerbage2)
        m = -1
        linitr = 1
        columnWidth = 50
        just = RichColumnar(theVerbage2, columnWidth)
        # verbage = theVerbage2
        lines = just.getLines()
        # print lines
        totalLines = just.countLines()
        p = 0
        verbage = ""
        linewidth = width * 1.2
        theStyle = "width:" + str(linewidth) + "px;text-align:justify;font-size:12pt"
        if offsetY > 0:
            useThisOffsetY = 200 + offsetY
            theStyle += ";top:" + str(offsetY) + "px;position:absolute;"
        else:
            useThisOffsetY = 50
            theStyle += ";top:" + str(useThisOffsetY) + "px;position:absolute;"
        if offsetX > 0:
            useThisOffsetX = 50 + offsetX
            theStyle += "left:" + str(useThisOffsetX) + "px;"
        else:
            useThisOffsetX = 0
            theStyle += "left:" + str(useThisOffsetX) + "px;"
        rich += "<div style='" + theStyle + "' class='richline'>"
        enoughLines = 0.52 * (totalLines - snapline)
        if enoughLines + snapline >= totalLines:
            thisLinesCount = totalLines
        else:
            thisLinesCount = enoughLines + snapline
        while p < thisLinesCount:
            if p >= snapline:
                verbage = lines[p]
                rich += verbage.decode("utf-8")
            p += 1
        rich += "</div>"
        arich = ""
        arich += "<div><a href='"
        arich += self.aq_inner.aq_parent.absolute_url()
        arich += "/fullview"
        arich += "'>Read More</a></div>"
        # wordageURL = article.absolute_url()
        arich += "<div><a href='"
        # arich += wordageURL
        arich += "'>Edit</a></div>"
        arich += "</div>"
        return (rich, 0, 0, enoughLines + snapline)
示例#2
0
	def alltext(self,width,height):
		"""
		Test
		"""
		rich = "<div class='richcolumn'>"
		articles = self.getArticle()
		for article in articles:
			theWordage = article.getWordage()
		# get rid of tags
		theVerbage = re.sub("<.>","",theWordage)
		theVerbage2 = re.sub("<\/.>","",theVerbage)
		wordlen = len(theVerbage2)
		m = -1
		linitr = 1
		columnWidth = 50
		just = RichColumnar(theVerbage2,columnWidth)
		lines = just.getLines()
		#print lines
		totalLines = just.countLines()
		p = 0 
		verbage = ""
		linewidth = width * 1.2
		theStyle='width:'+str(linewidth)+'px;text-align:justify;font-size:12pt'
		rich += "<div style='"+theStyle+"' class='richline'>"
		while p <= totalLines:
			verbage=just.returnLine(p)
			rich += verbage.decode('utf-8')
			p += 1
		rich += "</div>"
		rich += "</div>"
		return rich
示例#3
0
	def getHeight(self):
		"""
		Return the Height in px that was requested by this RichColumn
		"""
		y = 0
		width = self.getCharsPerLine() * 6
		articles = self.getArticle()
		output = []
		theParagraph = True 
		theCarrotStart = False
		theCarrotEnd = False
		theTagOpen = True
		theTag = ""
		theWordage = " "
		gotTheTag = False
		gotEndTag = False
		nasty = 'Â'
		for article in articles:
			#print article
			verbage = article.getWordage()
			#print verbage
			verblen = len(verbage)
			#print verblen
			m = -1
			# while within a paragraph
			total = self.getStartLine()
			i = 0
			indent = False
			gotEndTag = False
			theWordage = verbage 
			moreChars = int(self.getCharsPerLine()*2)
			indent = True
			just = RichColumnar(theWordage,self.getCharsPerLine())
			lines = just.getLines()
			#print lines
			totalLines = just.countLines()
			p = 0 
			i = 0
			while p <= totalLines and i<self.getEndLine():
				if i >= self.getStartLine():
					theLine = just.returnLine(p)
					#print theLine
					if  theLine[:4]=="----":
						indent=True
					else:
						indent=False
					if indent:
						indent=False
						#self.drawALine(c,x+8,y,theLine[4:],True)
						y += 12 
					else:
						y += 12 
				p += 1
				i += 1
			theWordage = " "
			total += i
		return y
示例#4
0
	def getSnapshot(self,width,height):
		"""
		Test
		"""
		diagnostic = "<div>RichColumn: getSnapshot</div>"
		diagnostic += "<div>    height: %i px</div>" % height
		diagnostic += "<div>    12pt is 16px</div>"
		numberOfLines = int(height / 16)
		diagnostic += "<div>    number of lines: %i</div>" % numberOfLines
		rich = "<div class='richcolumn'>"
		articles = self.getArticle()
		for article in articles:
			theWordage = article.getWordage()
		# get rid of tags
		theVerbage = re.sub("<.>","",theWordage)
		theVerbage2 = re.sub("<\/.>","",theVerbage)
		wordlen = len(theVerbage2)
		m = -1
		linitr = 1
		columnWidth = 50
		just = RichColumnar(theVerbage2,columnWidth)
		lines = just.getLines()
		#print lines
		totalLines = just.countLines()
		p = 0 
		verbage = ""
		linewidth = width * 1.2
		theStyle='width:'+str(linewidth)+'px;text-align:justify;font-size:12pt'
		rich += "<div style='"+theStyle+"' class='richline'>"
		while p <= totalLines:
			verbage=just.returnLine(p)
			#rich += verbage
			#rich += diagnostic 
			rich += verbage.decode('utf-8')
			#deduct from height
			#deduction = 26 * 4 / (3 * width / 320)
			#height -= deduction
			#if height <= 0:
			#    break
			p+=1
		rich += "</div>"
		rich += "<div><a href='"
		rich += self.aq_inner.aq_parent.absolute_url()
		rich += "/fullview"
		rich += "'>Read More</a></div>"
		wordageURL = article.absolute_url()
		rich += "<div><a href='"
		rich += wordageURL
		rich += "'>Edit</a></div>"
		rich += "</div>"
		return (rich,0,0)
示例#5
0
    def pdf(self,REQUEST): 
            """
   	    Test
            """
            skin = self.portal_skins.invoicing_templates
            showTemplate=skin.showIssue
	    output = StringIO()
	    c = canvas.Canvas(output,pagesize=letter,bottomup=0)
	    x=35
	    y=50
            textobject = c.beginText()
            textobject.setTextOrigin(x,y)
            textobject.setFont('Times-Roman',11)
	    xorig = x
	    yorig = y
	    xleft = 35
	    ytop = 35
	    ysave = y
	    width = self.getColumnSize() * 6
	    verbage = self.getWordage()
            theCarrotStart = False
            theCarrotEnd = False
            theTagOpen = True
            theTag = ""
            theWordage = " "
	    gotTheTag = False
	    nasty = 'Â'
	    verblen = len(verbage)
            m = -1
	    # while within a paragraph
	    total = 0
	    i = 0
	    while m < verblen-1:
		m += 1
		theChar = verbage[m]
		if theChar == '<':
		    theTag = ""
		    theCarrotStart = True
		    gotTheTag = True
                elif theChar == '/':
                    theTagOpen = False
		    theCarrotStart = False
		    gotTheTag = True
                elif theChar == '>':
                    theCarrotEnd = True
		    theCarrotStart = False
		    print "the tag %s" % theTag
		    gotTheTag = False 
		elif theCarrotStart and theChar != "<":
		    theTag += theChar
		    gotTheTag = True
		elif not gotTheTag:
		    if theChar != nasty:
		        theWordage += theChar
                if theCarrotEnd == True and theTagOpen == False:
		    theCarrotEnd = False
		    theTagOpen = True
		    just = RichColumnar(theWordage,self.getColumnSize())
		    lines = just.getLines()
		    totalLines = just.countLines()
		    p = 0 
		    while p <= totalLines and i<200:
			if i >=0:
			    theLine = just.returnLine(p)
			    self.drawALine(c,x,y,theLine)
			    y += 12 
			p += 1
			i += 1
		    theWordage = " "
		total += i
	    c.showPage()
	    c.save()
	    result = output.getvalue()
	    output.close()
	    response = REQUEST.RESPONSE
            response.setHeader('Content-type','application/pdf')
	    return result 
示例#6
0
    def returnLines(self):
        """
	    Test
	    """
        articles = self.getArticle()
        output = []
        theParagraph = True
        theCarrotStart = False
        theCarrotEnd = False
        theTagOpen = True
        theTag = ""
        theWordage = " "
        gotTheTag = False
        # nasty = 'Â'
        for article in articles:
            verbage = article.getWordage()
            verblen = len(verbage)
            m = -1
            # while within a paragraph
            while m < verblen - 1:
                m += 1
                theChar = verbage[m]
                if theChar == "<":
                    theTag = ""
                    theCarrotStart = True
                    gotTheTag = True
                    gotTheTag = False
                    theWordage += "\t"
                elif theChar == "/":
                    theTagOpen = False
                    theCarrotStart = False
                    gotTheTag = True
                    gotTheTag = False
                    theWordage += "\t"
                elif theChar == ">":
                    theCarrotEnd = True
                    theCarrotStart = False
                    # print "the tag %s" % theTag
                    gotTheTag = False
                    theWordage += "\t"
                elif theCarrotStart and theChar != "<":
                    theTag += theChar
                    gotTheTag = True
                elif not gotTheTag:
                    # if theChar != nasty:
                    theWordage += theChar
                elif theCarrotEnd == True and theTagOpen == False:
                    # print "wordage %s" % theWordage
                    useWordage = "\t"
                    useWordage += theWordage
                    theCarrotEnd = False
                    theTagOpen = True
                    moreChars = int(self.getCharsPerLine * 0.5)
                    # just = RichColumnar(theWordage,self.getCharsPerLine())
                    just = RichColumnar(useWordage, moreChars)
                    lines = just.getLines()
                    totalLines = just.countLines()
                    i = self.getStartLine()
                    while i <= totalLines and i < self.getEndLine():
                        theLine = just.returnLine(i)
                        output.append(theLine)
                        i += 1
                        # theWordage = " "
                useContinuedOn = self.getUseContinuedOn()
                if useContinuedOn:
                    theLine = self.getContinuedOn()
            output.append(theLine)
        return output
示例#7
0
    def callPDFPDTBySameName(self, c, x, y, REQUEST, parent, top, pagenumber):
        """
	    Test
	    """
        # print "I AM HERE"
        # print self.Title()
        y += 20
        xorig = x
        yorig = y - 20
        xleft = parent.getLeft()
        ytop = parent.getTop()
        glueX = self.getGlueX()
        glueY = self.getGlueY()
        if glueX:
            columnSpace = 15
            x += xleft - columnSpace
        y = 1160 - y
        ysave = y
        columncontainer = (
            "/opt/development/newholland/press/products/Newspaper/skins/newspaper_templates/" + self.Title()
        )
        obj = PDFPageTemplate(self.Title(), columncontainer)
        containerLeft = parent.getLeft()
        width = self.getCharsPerLine() * 6
        # result=obj.continuePDF(c,x,y+30,REQUEST,parent)
        offsetYHeight = self.getOffsetYHeight()
        offsetXWidth = self.getOffsetXWidth()
        x += offsetXWidth
        y -= offsetYHeight
        articles = self.getArticle()
        output = []
        theParagraph = True
        theCarrotStart = False
        theCarrotEnd = False
        theTagOpen = True
        theTag = ""
        theWordage = " "
        gotTheTag = False
        nasty = "Â"
        useContinuedFrom = self.getUseContinuedFrom()
        if useContinuedFrom:
            theLine = self.getContinuedFrom()
            self.drawALine(c, x, y, theLine, 0)
            y -= 24
        for article in articles:
            # print article
            verbage = article.getWordage()
            # print verbage
            verblen = len(verbage)
            # print verblen
            m = -1
            # while within a paragraph
            total = self.getStartLine()
            i = 0
            indent = False
            while m < verblen - 1:
                # print "am in"
                m += 1
                theChar = verbage[m]
                # print theChar
                if theChar == "<":
                    theTag = ""
                    theCarrotStart = True
                    gotTheTag = True
                elif theChar == "/":
                    theTagOpen = False
                    gotTheTag = True
                elif theChar == ">":
                    theCarrotEnd = True
                    theCarrotStart = False
                    # print "the tag %s" % theTag
                    gotTheTag = False
                elif theCarrotStart and theChar != "<":
                    theTag += theChar
                    gotTheTag = True
                elif not gotTheTag:
                    if theChar != nasty:
                        theWordage += theChar
                else:
                    theWordage += theChar
                    # print theWordage
                if theCarrotEnd == True and theTagOpen == False:
                    theCarrotEnd = False
                    theTagOpen = True
                    # print "theWordage"
                    moreChars = int(self.getCharsPerLine() * 2)
                    indent = True
                    # print theWordage
                    # just = RichColumnar(theWordage,self.getCharsPerLine())
                    just = RichColumnar(theWordage, self.getCharsPerLine())
                    lines = just.getLines()
                    # print lines
                    totalLines = just.countLines()
                    p = 0
                    while p <= totalLines and i < self.getEndLine():
                        if i >= self.getStartLine():
                            theLine = just.returnLine(p)
                            # print theLine
                            if indent:
                                indent = False
                                self.drawALine(c, x, y, theLine, 0)
                            else:
                                self.drawALine(c, x, y, theLine, 0)
                            y -= 12
                        p += 1
                        i += 1
                    theWordage = " "
                    just.deleteLines()
            total += i
        useContinuedOn = self.getUseContinuedOn()
        if useContinuedOn:
            theLine = self.getContinuedOn()
            self.drawALine(c, x, y, theLine, 0)
            # newx = x + containerLeft
        newx = x + containerLeft
        offsetX = self.getOffsetX()
        offsetXWidth = self.getOffsetXWidth()
        resetY = self.getResetY()
        columnWidth = int(5.7 * float(self.getCharsPerLine()))
        if offsetX:
            returnx = x + columnWidth
        else:
            returnx = newx + columnWidth
        if resetY:
            returny = yorig
            # returny = ysave - yorig
            # returny = ysave + 160
            if self.getAddLineHeight():
                returny -= 11
        else:
            returny = y - yorig
        return (returnx, returny)
示例#8
0
    def getHeight(self):
        """
	    TEST
	    """
        y = 0
        articles = self.getArticle()
        output = []
        theParagraph = True
        theCarrotStart = False
        theCarrotEnd = False
        theTagOpen = True
        theTag = ""
        theWordage = " "
        gotTheTag = False
        nasty = "Â"
        for article in articles:
            verbage = article.getWordage()
            verblen = len(verbage)
            m = -1
            total = self.getStartLine()
            i = 0
            indent = False
            while m < verblen - 1:
                m += 1
                theChar = verbage[m]
                if theChar == "<":
                    theTag = ""
                    theCarrotStart = True
                    gotTheTag = True
                elif theChar == "/":
                    theTagOpen = False
                    gotTheTag = True
                elif theChar == ">":
                    theCarrotEnd = True
                    theCarrotStart = False
                    # print "the tag %s" % theTag
                    gotTheTag = False
                elif theCarrotStart and theChar != "<":
                    theTag += theChar
                    gotTheTag = True
                elif not gotTheTag:
                    if theChar != nasty:
                        theWordage += theChar
                else:
                    theWordage += theChar
                    # print theWordage
                if theCarrotEnd == True and theTagOpen == False:
                    theCarrotEnd = False
                    theTagOpen = True
                    moreChars = int(self.getCharsPerLine() * 2)
                    indent = True
                    columnSize = self.getCharsPerLine()
                    just = RichColumnar(theWordage, columnSize)
                    lines = just.getLines()
                    totalLines = just.countLines()
                    p = 0
                    while p <= totalLines and i < self.getEndLine():
                        if i >= self.getStartLine():
                            theLine = just.returnLine(p)
                            y += 18
                        p += 1
                        i += 1
                    theWordage = " "
            total += i
        return y
示例#9
0
	def getJSON(self):
		"""
		Test
		"""
		json_items={}	
		json_items['charsPerLine']=self.getCharsPerLine()
		width = self.getCharsPerLine() * 6
		articles = self.getArticle()
		theParagraph = True 
		theCarrotStart = False
		theCarrotEnd = False
		theTagOpen = True
		theTag = ""
		theWordage = " "
		gotTheTag = False
		gotEndTag = False
		nasty = 'Â'
		for article in articles:
			#print article
			verbage = article.getWordage()
			#print verbage
			verblen = len(verbage)
			#print verblen
			m = -1
			# while within a paragraph
			total = self.getStartLine()
			i = 0
			indent = False
			gotEndTag = False
			theWordage = verbage 
			moreChars = int(self.getCharsPerLine()*2)
			indent = True
			just = RichColumnar(theWordage,self.getCharsPerLine())
			lines = just.getLines()
			#print lines
			totalLines = just.countLines()
			json_items['totalLines']=just.countLines()
			p = 0 
			i = 0
			json_lines = {}
			while p <= totalLines and i<self.getEndLine():
				if i >= self.getStartLine():
					theLine = just.returnLine(p)
					#print theLine
					if  theLine[:4]=="----":
						indent=True
					else:
						indent=False
					if indent:
						indent=False
						s = theLine[4:]
						s = s.decode('utf-8')
						t = u""
						for ii in s:
						    if ord(ii) in entity.codepoint2name:
							name = entity.codepoint2name.get(ord(ii))
							it = "&" + name + ';'
							t += it	
						    else:
							t += ii
						json_lines[i]=t
					else:
						s=theLine.decode('utf-8')
						t = u""
						for ii in s:
						    if ord(ii) in entity.codepoint2name:
							name = entity.codepoint2name.get(ord(ii))
							it = "&" + name + ';'
							t += it	
						    else:
							t += ii
						json_lines[i]=t
				p += 1
				i += 1
			theWordage = " "
			total += i
		useContinuedOn = self.getUseContinuedOn()
		if useContinuedOn:
			theLine = self.getContinuedOn()
			json_lines[i]=theLine
		#newx = x + containerLeft
		json_items['lines']=json_lines
                json_items['article']=self.getArticle()[0].getId()
                json_items['startLine']=self.getStartLine()
                json_items['endLine']=self.getEndLine()
                json_items['useRemainder']=self.getUseRemainder()
                json_items['useContinuedOn']=self.getUseContinuedOn()
                json_items['continuedOn']=self.getContinuedOn()
                json_items['useContinuedFrom']=self.getUseContinuedFrom()
                json_items['continuedFrom']=self.getContinuedFrom()
                json_items['charsPerLine']=self.getCharsPerLine()
                json_items['textclass']=self.getTextclass()
                json_items['addLineHeight']=self.getAddLineHeight()
		json_items['elements']=super(RichColumn,self).getJSON()
		return json_items
示例#10
0
	def callPDFPDTBySameName(self,c,x,y,REQUEST,parent,top,pagenumber):
		"""
		Test
		"""
		#print "I AM HERE"
		#print self.Title()
		#xleft = parent.getLeft()
		#ytop = parent.getTop()
		(x,y) = self.getPosition()
		y = 1185 - y
		columncontainer = '/opt/development/newholland/press/products/Newspaper/skins/newspaper_templates/'+self.Title()
		obj=PDFPageTemplate(self.Title(),columncontainer)
		containerLeft = parent.getLeft()
		width = self.getCharsPerLine() * 6
		#result=obj.continuePDF(c,x,y+30,REQUEST,parent)
		articles = self.getArticle()
		output = []
		theParagraph = True 
		theCarrotStart = False
		theCarrotEnd = False
		theTagOpen = True
		theTag = ""
		theWordage = " "
		gotTheTag = False
		gotEndTag = False
		nasty = 'Â'
		for article in articles:
			#print article
			verbage = article.getWordage()
			#print verbage
			verblen = len(verbage)
			#print verblen
			m = -1
			# while within a paragraph
			total = self.getStartLine()
			i = 0
			indent = False
			gotEndTag = False
			theWordage = verbage 
			moreChars = int(self.getCharsPerLine()*2)
			indent = True
			just = RichColumnar(theWordage,self.getCharsPerLine())
			lines = just.getLines()
			#print lines
			totalLines = just.countLines()
			p = 0 
			i = 0
			while p <= totalLines and i<self.getEndLine():
				if i >= self.getStartLine():
					theLine = just.returnLine(p)
					#print theLine
					if  theLine[:4]=="----":
						indent=True
					else:
						indent=False
					if indent:
						indent=False
						self.drawALine(c,x+8,y,theLine[4:],True)
						y -= 12 
					else:
						self.drawALine(c,x,y,theLine,False)
						y -= 12 
				p += 1
				i += 1
			theWordage = " "
			total += i
		useContinuedOn = self.getUseContinuedOn()
		if useContinuedOn:
			theLine = self.getContinuedOn()
			self.drawALine(c,x,y,theLine,False)
		#newx = x + containerLeft
		newx = x + containerLeft
		return (x,y)