def image_spices(an_odt, a_spice, a_font):
	## graphic
	image_stylename = a_spice + "frame_style"
	image_graphic_style = Style(name=image_stylename, family="graphic")
	href = an_odt.addPicture(a_spice + ".jpg")
	if a_spice == "chocolade":
		backgroundimage = BackgroundImage(href=href, position="top left", repeat="no")
	elif a_spice == "koraal":
		backgroundimage = BackgroundImage(href=href, position="bottom right", repeat="no")
	else:
		backgroundimage = BackgroundImage(href=href, position="top left", repeat="repeat")
	image_graphic_properties = GraphicProperties(border="0.5mm double #000000")
	image_graphic_properties.addElement(backgroundimage)
	image_graphic_style.addElement(image_graphic_properties)
	image_beehive = beehive(an_odt, image_graphic_style,
							"273mm", "194mm", "-12mm", "-12mm", "1")
	image_frame = image_beehive["frame"]
	image_textbox = image_beehive["textbox"]

	## textgraph
	image_stylename = "emptygif"
	image_textgraph_style = Style(name=image_stylename, family="paragraph")
	image_text_props = TextProperties()
	image_textgraph_style.addElement(image_text_props)
	image_paragraph_props = ParagraphProperties()
	image_textgraph_style.addElement(image_paragraph_props)
	an_odt.styles.addElement(image_textgraph_style)

	text_unit(an_odt, image_textgraph_style, u"", image_textbox)

	an_odt.text.addElement(image_frame)
Exemple #2
0
def extract_highlight_odf(name, img_quality, two_col, output_folder=None):
    textdoc = OpenDocumentText()
    doc_mask = fitzopen(name)
    doc_text = fitzopen(name)
    nb_pages = doc_text.pageCount
    #create style for paragraph
    style_p = Style(name="P1", family="paragraph", parentstylename="Standard")
    p_prop = ParagraphProperties(textalign="justify",
                                 justifysingleword="false")
    style_p.addElement(p_prop)
    textdoc.automaticstyles.addElement(style_p)

    #create style for images
    style_i = Style(name="fr1", family="graphic", parentstylename="Graphics")
    i_prop = GraphicProperties(wrap="none",
                               runthrough="foreground",
                               horizontalpos="center",
                               horizontalrel="paragraph")
    style_i.addElement(i_prop)
    textdoc.automaticstyles.addElement(style_i)

    #insert pdf file name
    textdoc.text.addElement(P(stylename=style_p, text=f"{name}\n\n"))

    #isolate highlights in _mask and text in _text
    doc_mask, doc_text = Page_Get_Highlights(doc_mask, doc_text)

    #iterate over pages to create rectangles to extract
    for i in range(nb_pages):

        if two_col == True:
            #colonnes
            for col in [1, 2]:
                rect, hierarchy, Xrects = Page_Get_Rects(doc_mask[i], col)

                if rect.shape[0] > 0:
                    textdoc = Page_Rect_get_Text_odf(doc_text, i, rect,
                                                     hierarchy, Xrects,
                                                     textdoc, style_p, style_i,
                                                     img_quality, col)
        else:
            col = 0
            rect, hierarchy, Xrects = Page_Get_Rects(doc_mask[i], col)
            if rect.shape[0] > 0:
                textdoc = Page_Rect_get_Text_odf(doc_text, i, rect, hierarchy,
                                                 Xrects, textdoc, style_p,
                                                 style_i, img_quality, col)
    if output_folder is not None:
        basename = os.path.basename(name)
        outname = basename.replace(".pdf", ".odt")
        outname = os.path.join(output_folder, outname)
        textdoc.save(outname)
    else:
        textdoc.save(name.replace(".pdf", ".odt"))
    doc_mask.close()
    doc_text.close()
Exemple #3
0
 def __init__(self, name):
     self.name = name
     self.document = OpenDocumentText()
     self.current_page = None
     self.photo_style = Style(name="Photo", family="graphic")
     self.document.styles.addElement(self.photo_style)
     self.font_styles = []
     self.page_layouts = []
     self.page_masters = []
     self.page_styles = []
     self.temp_images = []
     frame_style = Style(name='FrameStyle', family='graphic')
     frame_style.addElement(GraphicProperties(borderlinewidth='none'))
     self.document.styles.addElement(frame_style)
     frame_style_rotated = Style(name='FrameStyleRotated', family='graphic')
     frame_style_rotated.addElement(
         GraphicProperties(fill='none',
                           stroke='none',
                           verticalpos='from-top',
                           verticalrel='paragraph'))
     self.document.automaticstyles.addElement(frame_style_rotated)
Exemple #4
0
    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    doc.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(
        PageLayoutProperties(margin="0pt",
                             pagewidth="800pt",
                             pageheight="600pt",
                             printorientation="landscape"))

    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    titlestyle = Style(name="MyMaster-title", family="presentation")
    titlestyle.addElement(ParagraphProperties(textalign="center"))
    titlestyle.addElement(TextProperties(fontsize="34pt"))
    titlestyle.addElement(GraphicProperties(fillcolor="#ffff99"))
    doc.styles.addElement(titlestyle)

    # Style for the photo frame
    photostyle = Style(name="MyMaster-photo", family="presentation")
    doc.styles.addElement(photostyle)

    # Create automatic transition
    dpstyle = Style(name="dp1", family="drawing-page")
    dpstyle.addElement(
        DrawingPageProperties(transitiontype="automatic",
                              transitionstyle="move-from-top",
                              duration="PT5S"))
    doc.automaticstyles.addElement(dpstyle)

    # Every drawing page must have a master page assigned to it.
def do_job(job):
    """Do something"""
    warnings = get_warnings(job['sts'], job['ets'], job['wfo'], job['wtype'])

    mydir = "%s/%s" % (TMPDIR, job['jobid'])
    if not os.path.isdir(mydir):
        os.makedirs(mydir)
    os.chdir(mydir)

    basefn = "%s-%s-%s-%s-%s" % (job['wfo'], job['wtype'].replace(
        ",", "_"), job['radar'], job['sts'].strftime("%Y%m%d%H"),
                                 job['ets'].strftime("%Y%m%d%H"))
    outputfile = "%s.odp" % (basefn, )

    doc = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    doc.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(
        PageLayoutProperties(margin="0pt",
                             pagewidth="800pt",
                             pageheight="600pt",
                             printorientation="landscape"))

    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    titlestyle = Style(name="MyMaster-title2", family="presentation")
    titlestyle.addElement(ParagraphProperties(textalign="center"))
    titlestyle.addElement(TextProperties(fontsize="34pt"))
    titlestyle.addElement(GraphicProperties(fillcolor="#ffff99"))
    doc.styles.addElement(titlestyle)

    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    indexstyle = Style(name="MyMaster-title", family="presentation")
    indexstyle.addElement(ParagraphProperties(textalign="center"))
    indexstyle.addElement(TextProperties(fontsize="28pt"))
    indexstyle.addElement(GraphicProperties(fillcolor="#ffffff",
                                            stroke="none"))
    doc.styles.addElement(indexstyle)

    # Style for the photo frame
    photostyle = Style(name="MyMaster-photo", family="presentation")
    doc.styles.addElement(photostyle)

    # Every drawing page must have a master page assigned to it.
    masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout)
    doc.masterstyles.addElement(masterpage)

    dpstyle = Style(name="dp1", family="drawing-page")
    # dpstyle.addElement(DrawingPageProperties(transitiontype="automatic",
    #   transitionstyle="move-from-top", duration="PT5S"))
    doc.automaticstyles.addElement(dpstyle)

    # Title slide
    page = Page(masterpagename=masterpage)
    doc.presentation.addElement(page)
    frame = Frame(stylename=indexstyle,
                  width="720pt",
                  height="500pt",
                  x="40pt",
                  y="10pt")
    page.addElement(frame)
    textbox = TextBox()
    frame.addElement(textbox)
    textbox.addElement(P(text="IEM Raccoon Report"))

    frame = Frame(stylename=indexstyle,
                  width="720pt",
                  height="500pt",
                  x="40pt",
                  y="150pt")
    page.addElement(frame)
    textbox = TextBox()
    frame.addElement(textbox)
    textbox.addElement(P(text="WFO: %s" % (job['wfo'], )))
    textbox.addElement(
        P(text=("Radar: %s Product: %s"
                "") % (job['radar'], job['nexrad_product'])))
    textbox.addElement(P(text="Phenomenas: %s" % (job['wtype'], )))
    textbox.addElement(
        P(text="Start Time: %s UTC" % (job['sts'].strftime("%d %b %Y %H"), )))
    textbox.addElement(
        P(text="End Time: %s UTC" % (job['ets'].strftime("%d %b %Y %H"), )))
    textbox.addElement(P(text=""))
    textbox.addElement(P(text="Raccoon Version: %s" % (__REV__, )))
    textbox.addElement(
        P(text="Generated on: %s" %
          (datetime.datetime.utcnow().strftime("%d %b %Y %H:%M %Z"))))
    textbox.addElement(P(text=""))
    textbox.addElement(
        P(text="Bugs/Comments/Yelling?: daryl herzmann [email protected]"))

    i = 0
    for warning in warnings:
        # Make Index page for the warning
        page = Page(masterpagename=masterpage)
        doc.presentation.addElement(page)
        titleframe = Frame(stylename=indexstyle,
                           width="700pt",
                           height="500pt",
                           x="10pt",
                           y="10pt")
        page.addElement(titleframe)
        textbox = TextBox()
        titleframe.addElement(textbox)
        textbox.addElement(
            P(text="%s.O.NEW.K%s.%s.W.%04i" %
              (job['sts'].year, job['wfo'], warning['phenomena'],
               warning['eventid'])))
        textbox.addElement(
            P(text="Issue: %s UTC" %
              (warning['issue'].strftime("%d %b %Y %H:%M"), )))
        textbox.addElement(
            P(text="Expire: %s UTC" %
              (warning['expire'].strftime("%d %b %Y %H:%M"), )))
        textbox.addElement(
            P(text="Poly Area: %.1f sq km (%.1f sq mi) [%.1f%% vs County]" %
              (warning['polyarea'], warning['polyarea'] * 0.386102,
               warning['polyarea'] / warning['countyarea'] * 100.0)))
        textbox.addElement(
            P(text="County Area: %.1f square km (%.1f square miles)" %
              (warning['countyarea'], warning['countyarea'] * 0.386102)))

        url = ("http://iem.local/GIS/radmap.php?"
               "layers[]=places&layers[]=legend&layers[]=ci&layers[]=cbw"
               "&layers[]=sbw&layers[]=uscounties&layers[]=bufferedlsr"
               "&lsrbuffer=15")
        url += "&vtec=%s.O.NEW.K%s.%s.W.%04i" % (job['sts'].year, job['wfo'],
                                                 warning['phenomena'],
                                                 warning['eventid'])

        cmd = "wget -q -O %i.png '%s'" % (i, url)
        os.system(cmd)
        photoframe = Frame(stylename=photostyle,
                           width="480pt",
                           height="360pt",
                           x="160pt",
                           y="200pt")
        page.addElement(photoframe)
        href = doc.addPicture("%i.png" % (i, ))
        photoframe.addElement(Image(href=href))
        i += 1

        times = []
        now = warning['issue']
        while now < warning['expire']:
            times.append(now)
            now += datetime.timedelta(minutes=15)
        times.append(warning['expire'] - datetime.timedelta(minutes=1))

        for now in times:
            page = Page(stylename=dpstyle, masterpagename=masterpage)
            doc.presentation.addElement(page)
            titleframe = Frame(stylename=titlestyle,
                               width="720pt",
                               height="56pt",
                               x="40pt",
                               y="10pt")
            page.addElement(titleframe)
            textbox = TextBox()
            titleframe.addElement(textbox)
            textbox.addElement(
                P(text="%s.W.%04i Time: %s UTC" %
                  (warning['phenomena'], warning['eventid'],
                   now.strftime("%d %b %Y %H%M"))))

            if job['nexrad_product'] == 'N0U':
                if now < SUPER_RES:
                    n0qn0r = 'N0V'
                else:
                    n0qn0r = 'N0U'
            else:
                if now < SUPER_RES:
                    n0qn0r = 'N0R'
                else:
                    n0qn0r = 'N0Q'

            url = "http://iem.local/GIS/radmap.php?"
            url += "layers[]=ridge&ridge_product=%s&ridge_radar=%s&" % (
                n0qn0r, job['radar'])
            url += "layers[]=sbw&layers[]=sbwh&layers[]=uscounties&"
            url += "layers[]=lsrs&ts2=%s&" % ((
                now + datetime.timedelta(minutes=15)).strftime("%Y%m%d%H%M"), )
            url += "vtec=%s.O.NEW.K%s.%s.W.%04i&ts=%s" % (
                job['sts'].year, job['wfo'], warning['phenomena'],
                warning['eventid'], now.strftime("%Y%m%d%H%M"))

            cmd = "wget -q -O %i.png '%s'" % (i, url)
            os.system(cmd)
            photoframe = Frame(stylename=photostyle,
                               width="640pt",
                               height="480pt",
                               x="80pt",
                               y="70pt")
            page.addElement(photoframe)
            href = doc.addPicture("%i.png" % (i, ))
            photoframe.addElement(Image(href=href))
            i += 1

    doc.save(outputfile)
    del doc
    cmd = "unoconv -f ppt %s" % (outputfile, )
    subprocess.call(cmd, shell=True)
    pptfn = "%s.ppt" % (basefn, )
    print("Generated %s with %s slides" % (pptfn, i))
    if os.path.isfile(pptfn):
        print('...copied to webfolder')
        shutil.copyfile(pptfn, "/mesonet/share/pickup/raccoon/%s" % (pptfn, ))
        # Cleanup
        os.chdir(TMPDIR)
        subprocess.call("rm -rf %s" % (job['jobid'], ), shell=True)
    else:
        print("Uh oh, no output file, lets kill soffice.bin")
        subprocess.call("pkill --signal 9 soffice.bin", shell=True)
        add_job(job)
Exemple #6
0
#h = Header()
#hp = P(text="2. ebaluazioko txostena")
#h.addElement(hp)
#mp.addElement(h)

# Create a style for the paragraph with page-break
withbreak = Style(name="WithBreak",
                  parentstylename="Standard",
                  family="paragraph")
withbreak.addElement(ParagraphProperties(breakbefore="page"))
textdoc.automaticstyles.addElement(withbreak)

h1style = Style(name="Heading 1",
                family="paragraph",
                parentstylename="Heading 1")
h1style.addElement(GraphicProperties(fill="solid", fillcolor="#e6e6ff"))
h1style.addElement(
    TextProperties(attributes={
        'fontsize': "14pt",
        'fontweight': "bold",
        'color': "#000099"
    }))
h1style.addElement(
    ParagraphProperties(breakbefore="page",
                        margintop="0.4cm",
                        marginbottom="0.2cm",
                        backgroundcolor="#e6e6ff",
                        padding="0.05cm",
                        borderleft="none",
                        borderright="none",
                        bordertop="none",
Exemple #7
0
def process_user_image_files(emailaddr):
    pagewidth = 800
    pageheight = 600
    logging.debug("cur_path %s" % (os.path.realpath('.'),) )
    odpfile = 'frieda_%s_%s.odp' % (emailaddr, time.strftime('%b_%d_%Y_%I%M%P'))
    ppt_content = []

    file_list = []
    for wroot, wsubdir, wfiles in os.walk('.'):
        wfiles = sort_files_by_time(wfiles, wroot)
        wsubdir = sort_files_by_time(wsubdir, wroot)
        cnt = 0
        for f in wfiles:
            cnt += 1
            file_list.append(os.path.join(wroot, f))
        if cnt != 0:
            wroot2 = '/' if len(wroot) < 2 else wroot[1:]
            ppt_content.append((wroot2, cnt))

    logging.debug('file_list: %r' % file_list)
    doc = OpenDocumentPresentation()
    pagelayout = PageLayout(name="MyLayout")
    pagelayout.addElement(PageLayoutProperties(backgroundcolor="#000000", margin="0pt", pagewidth="%dpt" %pagewidth,
                                               pageheight="%dpt" % pageheight, printorientation="landscape"))
    doc.automaticstyles.addElement(pagelayout)
    photostyle = Style(name="RadTeaching-photo", family="presentation")
    doc.styles.addElement(photostyle)
    dstyle = Style(name="d", family="drawing-page")
    dstyle.addElement(GraphicProperties(fillcolor="#000000"))
    dstyle.addElement(DrawingPageProperties(fill=True,
                                            fillcolor="#000000"))
    doc.automaticstyles.addElement(dstyle)


    masterpage = MasterPage(name="RadTeaching", pagelayoutname=pagelayout)
    doc.masterstyles.addElement(masterpage)
    images_added = 0
    # os.chdir(subdir)
    for picture in file_list:
        try:
            pictdata = open(picture).read()
            logging.debug("Adding %s" % (picture))
        except:
            logging.debug("Skipping %s" % (picture))
            continue
        ct,w,h = getImageInfoFileName(picture)
        if ct == 'not image':
            if picture[-4:] == '.dcm':
                png_picture = picture.replace('.dcm','.png')
                logging.debug("Converting %s to %s" % (picture, png_picture) )
                run_command(""" dcmj2pnm +on +Wi 1 %s %s """ % (picture, png_picture))
                picture = png_picture
                ct,w,h = getImageInfoFileName(picture)

        if ct not in ("jpeg", "jpg", "tiff", "png", "bmp", "gif", "tif"):
            logging.debug("Skipping %s unrecognized type %s" % (picture,ct) )
            continue
        if ct == "tiff" or ct == "tif":
            png_picture = picture.replace(".tiff",".tif").replace(".tif", ".png")
            logging.debug("Converting %s to %s" % (picture, png_picture))
            img = PythonMagick.Image()
            img.read(picture)
            if img.depth() > 8: # powerpoint can't handle 16 bit TIFF images.
                img.write(png_picture)
                del img
                picture = png_picture
                ct,w,h = getImageInfoFileName(picture)

        images_added += 1
        if w*pageheight > h*pagewidth: #check if width or height is limit to zooming
            h = float(h) * (pagewidth-2.0)/float(w)
            w = pagewidth - 2.0
        else:
            w = float(w)*(pageheight-2.0) / float(h)
            h = pageheight -2.0

        page = Page(stylename=dstyle, masterpagename=masterpage)
        doc.presentation.addElement(page)

        offsetx = (pagewidth - w)/2.0
        offsety = (pageheight - h)/2.0
        photoframe = Frame(stylename=photostyle, width='%fpt' % w, height='%fpt' % h,
                           x = '%fpt' % offsetx, y='%fpt' % offsety)
        page.addElement(photoframe)
        href = doc.addPicture(picture)
        photoframe.addElement(Image(href=href))

    if images_added > 0:
        logging.debug('Saving ODP as %s/%s' % (os.path.realpath('.'), odpfile))
        doc.save(odpfile)
    return (odpfile, images_added, ppt_content) if images_added > 0 else (False, 0, None)
Exemple #8
0
 def addGraphicStyle(self, id, name, graphic_properties={}):
     style = Style(name=name, family="graphic")
     if len(graphic_properties)>0:
         style.addElement(GraphicProperties(**graphic_properties))
     setattr(self, id, style)
     self.document.styles.addElement(style)
Exemple #9
0
    def test_chart_style(self):
        """ Test that chart:style-name reference is seen in content.xml """
        doc = OpenDocumentChart()
        chartstyle = Style(name="chartstyle", family="chart")
        chartstyle.addElement(
            GraphicProperties(stroke="none", fillcolor="#ffffff"))
        doc.automaticstyles.addElement(chartstyle)

        mychart = chart.Chart(width="576pt",
                              height="504pt",
                              stylename=chartstyle,
                              attributes={'class': 'chart:bar'})
        doc.chart.addElement(mychart)

        # Add title
        titlestyle = Style(name="titlestyle", family="chart")
        titlestyle.addElement(GraphicProperties(stroke="none", fill="none"))
        titlestyle.addElement(
            TextProperties(fontfamily="'Nimbus Sans L'",
                           fontfamilygeneric="swiss",
                           fontpitch="variable",
                           fontsize="13pt"))
        doc.automaticstyles.addElement(titlestyle)

        mytitle = chart.Title(x="385pt", y="27pt", stylename=titlestyle)
        mytitle.addElement(text.P(text="Title"))
        mychart.addElement(mytitle)

        # Add subtitle
        subtitlestyle = Style(name="subtitlestyle", family="chart")
        subtitlestyle.addElement(GraphicProperties(stroke="none", fill="none"))
        subtitlestyle.addElement(
            TextProperties(fontfamily="'Nimbus Sans L'",
                           fontfamilygeneric="swiss",
                           fontpitch="variable",
                           fontsize="10pt"))
        doc.automaticstyles.addElement(subtitlestyle)

        subtitle = chart.Subtitle(x="0pt", y="123pt", stylename=subtitlestyle)
        subtitle.addElement(text.P(text="my subtitle"))
        mychart.addElement(subtitle)

        # Legend
        legendstyle = Style(name="legendstyle", family="chart")
        legendstyle.addElement(GraphicProperties(fill="none"))
        legendstyle.addElement(
            TextProperties(fontfamily="'Nimbus Sans L'",
                           fontfamilygeneric="swiss",
                           fontpitch="variable",
                           fontsize="6pt"))
        doc.automaticstyles.addElement(legendstyle)

        mylegend = chart.Legend(legendposition="end",
                                legendalign="center",
                                stylename=legendstyle)
        mychart.addElement(mylegend)

        # Plot area
        plotstyle = Style(name="plotstyle", family="chart")
        plotstyle.addElement(
            ChartProperties(seriessource="columns",
                            percentage="false",
                            stacked="false",
                            threedimensional="true"))
        doc.automaticstyles.addElement(plotstyle)

        plotarea = chart.PlotArea(datasourcehaslabels="both",
                                  stylename=plotstyle)
        mychart.addElement(plotarea)

        # Style for the X,Y axes
        axisstyle = Style(name="axisstyle", family="chart")
        axisstyle.addElement(ChartProperties(displaylabel="true"))
        doc.automaticstyles.addElement(axisstyle)

        # Title for the X axis
        xaxis = chart.Axis(dimension="x",
                           name="primary-x",
                           stylename=axisstyle)
        plotarea.addElement(xaxis)
        xt = chart.Title()
        xaxis.addElement(xt)
        xt.addElement(text.P(text="x_axis"))

        # Title for the Y axis
        yaxis = chart.Axis(dimension="y",
                           name="primary-y",
                           stylename=axisstyle)
        plotarea.addElement(yaxis)
        yt = chart.Title()
        yaxis.addElement(yt)
        yt.addElement(text.P(text="y_axis"))

        result = doc.contentxml()  # contentxml() is supposed to yeld a bytes
        self.assertNotEqual(-1, result.find(b'''style:family="chart"'''))
Exemple #10
0
        maxy = int(reduce(max,yvals)) + 1
        miny = int(reduce(min,yvals))
        return minx, miny, maxx-minx, maxy-miny


# Create the document
doc = OpenDocumentDrawing()

# Create the drawing page
dpstyle = Style(family="drawing-page",name="DP1")
dpstyle.addElement(DrawingPageProperties(backgroundsize="border", fill="none"))
doc.automaticstyles.addElement(dpstyle)

# The blue background style of the flag
backgroundstyle = Style(family="graphic", name="blueback")
backgroundstyle.addElement(GraphicProperties(fill="solid", fillcolor="#003399", stroke="none"))
doc.automaticstyles.addElement(backgroundstyle)

# The style for the stars
starstyle = Style(family="graphic", name="starstyle")
starstyle.addElement(GraphicProperties(fill="solid", fillcolor="#ffcc00", stroke="none"))
doc.automaticstyles.addElement(starstyle)

# Create page layout specifying dimensions
plstyle = PageLayout(name="PM1")
plstyle.addElement(PageLayoutProperties(margin="0cm", pageheight="120mm", pagewidth="180mm", printorientation="portrait"))
doc.automaticstyles.addElement(plstyle)

# Create a master page
masterpage = MasterPage(stylename=dpstyle, name="Default", pagelayoutname=plstyle)
doc.masterstyles.addElement(masterpage)
Exemple #11
0
    def __init__(self):
        self.textdoc = OpenDocumentText()
        
        self.oneandhalflines = Style(name="oneandhalflines", parentstylename="Standard", family="paragraph")
        self.oneandhalflines.addElement(ParagraphProperties(lineheight="1.5"))
        self.textdoc.automaticstyles.addElement(self.oneandhalflines)
        
        # Create a style for the paragraph with page-break
        self.withbreak = Style(name="WithBreak", parentstylename="Standard", family="paragraph")
        self.withbreak.addElement(ParagraphProperties(breakbefore="page"))
        self.textdoc.automaticstyles.addElement(self.withbreak)

        self.footercenterstyle = Style(name="footercenter", family="paragraph", parentstylename="Standard")
        self.footercenterstyle.addElement(ParagraphProperties(textalign="center"))
        self.textdoc.automaticstyles.addElement(self.footercenterstyle)

        self.footerstyle = FooterStyle()
        self.footerstyle.addElement(HeaderFooterProperties(padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="none",shadow="none", minheight="1cm"))

        #Text Header
        self.plheaderstyle = PageLayout(name="pl")
        self.plheaderstyle.addElement(PageLayoutProperties(marginleft="2cm",marginright="2cm",margintop="1cm",marginbottom="1cm"))
        self.headerstyle = HeaderStyle()
        self.headerstyle.addElement(HeaderFooterProperties(backgroundcolor="#e6e6ff",padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="2.01pt solid #000099",shadow="none", minheight="1cm"))
        self.plheaderstyle.addElement(self.headerstyle)
        self.plheaderstyle.addElement(self.footerstyle)
        self.textdoc.automaticstyles.addElement(self.plheaderstyle)
        
        #image header
        self.pliheaderstyle = PageLayout(name="pli")
        self.pliheaderstyle.addElement(PageLayoutProperties(marginleft="2cm",marginright="2cm",margintop="1cm",marginbottom="1cm"))
        self.headeristyle = HeaderStyle()
        self.headeristyle.addElement(HeaderFooterProperties(padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="none",shadow="none", minheight="2cm"))
        self.pliheaderstyle.addElement(self.headeristyle)
        self.pliheaderstyle.addElement(self.footerstyle)   
        self.textdoc.automaticstyles.addElement(self.pliheaderstyle)
        
        self.h1style = Style(name="Heading 1",  family="paragraph",parentstylename="Heading 1")
        self.h1style.addElement(GraphicProperties(fill="solid",fillcolor="#e6e6ff"))
        self.h1style.addElement(TextProperties(attributes={'fontsize':"14pt",'fontweight':"bold",'color':"#000099" }))
        self.h1style.addElement(ParagraphProperties(breakbefore="page",margintop="0.4cm",marginbottom="0.2cm",backgroundcolor="#e6e6ff",padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="2.01pt solid #000099",shadow="none"))
        self.textdoc.automaticstyles.addElement(self.h1style)

        self.h2style = Style(name="Heading 2s", family="paragraph",parentstylename="Heading 2")
        self.h2style.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h2style.addElement(ParagraphProperties(marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h2style)
        
        self.h2bstyle = Style(name="Heading 2b", family="paragraph",parentstylename="Heading 2")
        self.h2bstyle.addElement(ParagraphProperties(breakbefore="page",marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h2bstyle)

        self.h3style = Style(name="Heading 3s", family="paragraph",parentstylename="Heading 3")
        self.h3style.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h3style.addElement(ParagraphProperties(marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h3style)
        self.h3bstyle = Style(name="Heading 3b", family="paragraph",parentstylename="Heading 3")
        self.h3bstyle.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h3bstyle.addElement(ParagraphProperties(breakbefore="page",marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h3bstyle)

        self.TAB_style = Style(name="Table", family="table-cell", parentstylename="Standard")
        self.TAB_style.addElement(TableCellProperties(border="0.05pt solid #000000"))
        self.textdoc.automaticstyles.addElement(self.TAB_style)

        self.TAB_stylered = Style(name="Table red", family="table-cell", parentstylename="Standard")
        self.TAB_stylered.addElement(TableCellProperties(backgroundcolor="ff0000",border="0.05pt solid #000000"))
        self.textdoc.automaticstyles.addElement(self.TAB_stylered)

        self.tableheaders = Style(name="Table Headers", family="paragraph", parentstylename="Standard")
        self.tableheaders.addElement(ParagraphProperties(numberlines="false", linenumber="0",textalign="center",margintop="0.2cm",marginbottom="0.2cm"))
        self.tableheaders.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold"}))
        self.textdoc.styles.addElement(self.tableheaders)

        self.tablecontents = Style(name="Table Contents", family="paragraph", parentstylename="Standard")
        self.tablecontents.addElement(ParagraphProperties(numberlines="false", linenumber="0",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontents.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontents)

        self.tablecontentscenter = Style(name="Table Contents Center", family="paragraph", parentstylename="Standard")
        self.tablecontentscenter.addElement(ParagraphProperties(numberlines="false", linenumber="0", textalign="center",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontentscenter.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontentscenter)

        self.tablecontentscenterred = Style(name="Table Contents Center Red", family="paragraph", parentstylename="Standard")
        self.tablecontentscenterred.addElement(ParagraphProperties(numberlines="false", linenumber="0", textalign="center", backgroundcolor="#ff0000",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontentscenterred.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontentscenterred)
Exemple #12
0
        xvals = [item[0] for item in self.polygon]
        maxx = int(reduce(max, xvals)) + 1
        minx = int(reduce(min, xvals))
        yvals = [item[1] for item in self.polygon]
        maxy = int(reduce(max, yvals)) + 1
        miny = int(reduce(min, yvals))
        return minx, miny, maxx - minx, maxy - miny


# Create the document
doc = OpenDocumentText()

# The blue background style of the flag
backgroundstyle = Style(family="graphic", name="blueback")
backgroundstyle.addElement(
    GraphicProperties(fill="solid", fillcolor="#003399", stroke="none"))
doc.automaticstyles.addElement(backgroundstyle)

# The style for the stars
starstyle = Style(family="graphic", name="starstyle")
starstyle.addElement(
    GraphicProperties(fill="solid", fillcolor="#ffcc00", stroke="none"))
doc.automaticstyles.addElement(starstyle)

# Create a paragraph to contain the drawing
drawpage = P()
doc.text.addElement(drawpage)

group = G()
drawpage.addElement(group)