def frag_text_language_check(context): if hasattr(context, 'language'): language = context.__getattribute__('language') for x in context.story: if hasattr(x, 'frags'): for y in x.frags: if hasattr(y, 'text'): text = y.text.strip() if text: detect_language_result = arabic_format( y.text, language) if detect_language_result is not None: y.text = detect_language_result
def addPara(self, force=False): force = (force or self.force) self.force = False # Cleanup the trail rfragList = reversed(self.fragList) # Find maximum lead maxLeading = 0 #fontSize = 0 for frag in self.fragList: leading = getSize(frag.leadingSource, frag.fontSize) + frag.leadingSpace maxLeading = max(leading, frag.fontSize + frag.leadingSpace, maxLeading) frag.leading = leading if force or (self.text.strip() and self.fragList): # Update paragraph style by style of first fragment first = self.fragBlock style = self.toParagraphStyle(first) # style.leading = first.leading + first.leadingSpace if first.leadingSpace: style.leading = maxLeading else: style.leading = getSize(first.leadingSource, first.fontSize) + first.leadingSpace bulletText = copy.copy(first.bulletText) first.bulletText = None # Add paragraph to story if force or len(self.fragAnchor + self.fragList) > 0: # We need this empty fragment to work around problems in # Reportlab paragraphs regarding backGround etc. if self.fragList: self.fragList.append(self.fragList[-1].clone(text='')) else: blank = self.frag.clone() blank.fontName = "Helvetica" blank.text = '' self.fragList.append(blank) self.dumpPara(self.fragAnchor + self.fragList, style) if hasattr(self, 'language'): language = self.__getattribute__('language') detect_language_result = arabic_format(self.text, language) if detect_language_result != None: self.text = detect_language_result para = PmlParagraph(self.text, style, frags=self.fragAnchor + self.fragList, bulletText=bulletText) para.outline = first.outline para.outlineLevel = first.outlineLevel para.outlineOpen = first.outlineOpen para.keepWithNext = first.keepWithNext para.autoLeading = "max" if self.image: para = PmlParagraphAndImage(para, self.image, side=self.imageData.get( "align", "left")) self.addStory(para) self.fragAnchor = [] first.bulletText = None # Reset data self.image = None self.imageData = {} self.clearFrag()