示例#1
0
    def __init__(self, my_page, my_draw_frame):
        """
        Build blockades and bbox
        """
        self.my_page = my_page
        self.my_draw_frame = my_draw_frame

        self.my_frame_class = my_draw_frame.get(PRESENTATION_CLASS_ATTR, '')

        # Start out with blockades the same as full page
        self.left_blockade = deepcopy(my_page.left_blockade)
        self.right_blockade = deepcopy(my_page.right_blockade)
        self.top_blockade = deepcopy(my_page.top_blockade)
        self.bottom_blockade = deepcopy(my_page.bottom_blockade)

        svg_x = force_svg_dim_to_float(
            my_draw_frame.get(force_to_tag('svg:x'), ''))
        svg_y = force_svg_dim_to_float(
            my_draw_frame.get(force_to_tag('svg:y'), ''))
        svg_w = force_svg_dim_to_float(
            my_draw_frame.get(force_to_tag('svg:width'), ''))
        svg_h = force_svg_dim_to_float(
            my_draw_frame.get(force_to_tag('svg:height'), ''))

        self.bbox = BBox(svg_x, svg_x + svg_w, svg_y, svg_y + svg_h)

        self.make_side_segments()  # for current state of BBox
示例#2
0
 def normalize_content_styles(self):
     
     self.draw_page_style_name = ''
     
     for elem in self.draw_page.iter():
         for aname, aval in elem.items():
             if aname.endswith( '}style-name' ):
                 a_new = self.presObj.get_next_a_style()
                 
                 elem.set( force_to_tag(aname), a_new )
                 style_elem = self.content_auto_styles.content_style_name_lookupD[ aval ]()
                 style_elem.set( force_to_tag('style:name'), a_new )
                 self.presObj.new_content_styleL.append( style_elem )
                 self.presObj.new_content_styleD[ a_new ] = style_elem
                 
                 if self.draw_page_style_name == '':
                     self.draw_page_style_name = a_new # first style-name is draw:page style:style
                 
                 if style_elem.tag == STYLE_STYLE_TAG:
                     sub_style_childL = style_elem.getchildren()
                     if sub_style_childL:
                         for sub_style_elem in sub_style_childL:
                             if sub_style_elem.tag == STYLE_DRAWING_PAGE_PROPS_TAG:
                                     sub_style_elem.set( PRESENTATION_BG_VISIBLE_ATTR, 'true' )
                 
                 
         if elem.get(DRAW_ID_ATTR, ''):
             if elem.tag != DRAW_PAGE_TAG:
                 id_new = self.presObj.get_next_draw_id()
                 elem.set(DRAW_ID_ATTR, id_new)
示例#3
0
 def normalize_content_styles(self):
     
     self.draw_page_style_name = ''
     
     for elem in self.draw_page.iter():
         for aname, aval in list(elem.items()):
             if aname.endswith( '}style-name' ):
                 a_new = self.presObj.get_next_a_style()
                 
                 elem.set( force_to_tag(aname), a_new )
                 style_elem = self.content_auto_styles.content_style_name_lookupD[ aval ]()
                 style_elem.set( force_to_tag('style:name'), a_new )
                 self.presObj.new_content_styleL.append( style_elem )
                 self.presObj.new_content_styleD[ a_new ] = style_elem
                 
                 if self.draw_page_style_name == '':
                     self.draw_page_style_name = a_new # first style-name is draw:page style:style
                 
                 if style_elem.tag == STYLE_STYLE_TAG:
                     sub_style_childL = style_elem.getchildren()
                     if sub_style_childL:
                         for sub_style_elem in sub_style_childL:
                             if sub_style_elem.tag == STYLE_DRAWING_PAGE_PROPS_TAG:
                                     sub_style_elem.set( PRESENTATION_BG_VISIBLE_ATTR, 'true' )
                 
                 
         if elem.get(DRAW_ID_ATTR, ''):
             if elem.tag != DRAW_PAGE_TAG:
                 id_new = self.presObj.get_next_draw_id()
                 elem.set(DRAW_ID_ATTR, id_new)
示例#4
0
 def set_image_href(self, frame_class='graphic', image_name='', num_image=0, keep_aspect_ratio=True):
     """
     Set the image xlink:href property in the draw:image element
     (perhaps adjust size and mark as "user-transformed")
     """
     DRAW_IMAGE_TAG = force_to_tag('draw:image')
             
     if image_name and (frame_class in self.draw_frameD):
     
         # make sure index does not overrun
         if num_image >= len(self.draw_frameD[frame_class]):
             print('...ERROR... image index too big in set_image_href')
             return
         
         draw_frame = self.draw_frameD[frame_class][num_image]
         frame_dim = self.frame_dimD[ draw_frame ]
                 
         elem = draw_frame.find( DRAW_IMAGE_TAG )
         if elem is not None:
             elem.set( force_to_tag('xlink:href'), 'media/%s'%image_name )
             
             if keep_aspect_ratio:
                 w_img,h_img = self.presObj.image_sizeD[ image_name ]
                 
                 # only continue if dimensions are available
                 if w_img and h_img:
                     w = float(w_img)
                     h = float(h_img)
                     frame_dim.set_aspect_ratio(w, h)
示例#5
0
 def set_image_href(self, frame_class='graphic', image_name='', num_image=0, keep_aspect_ratio=True):
     """
     Set the image xlink:href property in the draw:image element
     (perhaps adjust size and mark as "user-transformed")
     """
     DRAW_IMAGE_TAG = force_to_tag('draw:image')
             
     if image_name and (frame_class in self.draw_frameD):
     
         # make sure index does not overrun
         if num_image >= len(self.draw_frameD[frame_class]):
             print('...ERROR... image index too big in set_image_href')
             return
         
         draw_frame = self.draw_frameD[frame_class][num_image]
         frame_dim = self.frame_dimD[ draw_frame ]
                 
         elem = draw_frame.find( DRAW_IMAGE_TAG )
         if elem is not None:
             elem.set( force_to_tag('xlink:href'), 'media/%s'%image_name )
             
             if keep_aspect_ratio:
                 w_img,h_img = self.presObj.image_sizeD[ image_name ]
                 
                 # only continue if dimensions are available
                 if w_img and h_img:
                     w = float(w_img)
                     h = float(h_img)
                     frame_dim.set_aspect_ratio(w, h)
示例#6
0
    def set_all_styles_of_tag_w_attr(self, targ_tag, targ_attr_name,
                                     targ_attr_val, style_attr_name,
                                     style_attr_val):
        """
        dictionaries  hold style:name info (if init_all_annn_style8name)
        self.annn_style8nameD = {} # index=style:name ("a123"), value=elem
        self.style_refD = {} # index=xxxxx:style-name (e.g. "a123"), value=elem
        """
        targ_tag = force_to_tag(targ_tag)
        targ_attr_name = force_to_tag(targ_attr_name)
        style_attr_name = force_to_tag(style_attr_name)

        for elem in self.root.iter():
            # for example a 'draw:frame' with an attribute 'presentation:class' == "page-number",
            if (elem.tag == targ_tag) and (elem.get(targ_attr_name, '')
                                           == targ_attr_val):

                # looking for a style element attribute (e.g. an attrib value like "a123")
                for sub_elem in elem.iter():
                    # looking for, for example text:style-name="a28"
                    for attname, attval in list(sub_elem.items()):
                        if (attval in self.style_refD) and (
                                attval in self.annn_style8nameD):
                            style_elem = self.annn_style8nameD[attval]

                            # now look for the desired style attribute to set (e.g. 'fo:color' = '#000000')
                            for sub_style_elem in style_elem.iter():
                                if sub_style_elem.get(style_attr_name, ''):
                                    sub_style_elem.set(style_attr_name,
                                                       style_attr_val)
示例#7
0
    def set_all_styles_of_tag_w_attr(self, targ_tag, targ_attr_name, targ_attr_val,
                                         style_attr_name, style_attr_val):
        """
        dictionaries  hold style:name info (if init_all_annn_style8name)
        self.annn_style8nameD = {} # index=style:name ("a123"), value=elem
        self.style_refD = {} # index=xxxxx:style-name (e.g. "a123"), value=elem
        """
        targ_tag = force_to_tag( targ_tag )
        targ_attr_name = force_to_tag( targ_attr_name )
        style_attr_name = force_to_tag( style_attr_name )

        for elem in self.root.iter():
            # for example a 'draw:frame' with an attribute 'presentation:class' == "page-number",
            if (elem.tag == targ_tag) and (elem.get(targ_attr_name,'') == targ_attr_val):
                
                # looking for a style element attribute (e.g. an attrib value like "a123")
                for sub_elem in elem.iter():
                    # looking for, for example text:style-name="a28"
                    for attname, attval in sub_elem.items():
                        if (attval in self.style_refD)  and (attval in self.annn_style8nameD):
                            style_elem = self.annn_style8nameD[attval]
                            
                            # now look for the desired style attribute to set (e.g. 'fo:color' = '#000000')
                            for sub_style_elem in style_elem.iter():
                                if sub_style_elem.get(style_attr_name,''):
                                    sub_style_elem.set(style_attr_name, style_attr_val)
示例#8
0
 def set_all_attr_of_tag(self, tag, attr_name, attr_val):
     
     # force tag and attr_name to long version 
     tag = force_to_tag( tag )
     attr_name = force_to_tag( attr_name )
     
     for elem in self.root.iter():
         if elem.tag == tag:
             elem.set( attr_name, attr_val )
示例#9
0
    def set_all_attr_of_tag(self, tag, attr_name, attr_val):

        # force tag and attr_name to long version
        tag = force_to_tag(tag)
        attr_name = force_to_tag(attr_name)

        for elem in self.root.iter():
            if elem.tag == tag:
                elem.set(attr_name, attr_val)
示例#10
0
 def set_textspan_text(self, frame_class='title', text='My Text', num_frame=0, 
                          num_textspan=0, clear_all=True ):
     
     if frame_class in self.draw_frameD:
         try:
             draw_frame = self.draw_frameD[frame_class][num_frame]
         except:
             draw_frame = self.draw_frameD[frame_class][-1]
             print('...ERROR... in Page.set_textspan_text, num_frame>len(frameL)')
         
         # ============================================ outline =========================================
         if frame_class == 'outline':
             text_box = draw_frame.find( force_to_tag('draw:text-box') )
             text_listL = draw_frame.findall( force_to_tag('draw:text-box/text:list') )
             
             max_indent = len( text_listL )-1
             
             if (text_box is not None) and text_listL:
                 #print('max_indent of outline = %i'%max_indent)
                 text_box.clear_children()
                 
                 # text comes in w/o formatting for outline.
                 outlineL = self.build_outline_list( text )
                 for n, sInp in outlineL:
                     n = min(n, max_indent)
                     text_list = deepcopy( text_listL[n] )
                     
                     #annn_new = self.presObj.get_next_a_style()
                     #text_list.set( force_to_tag('style:name'), annn_new )
                     
                     text_span = None
                     target_tag = force_to_tag('text:span')
                     for elem in text_list.iter():
                         if elem.tag == target_tag:
                             text_span = elem
                             break
                     
                     if text_span is not None:
                         text_span.text = sInp
                         text_box.append( text_list )
             
             
         # ============================================ title/subtitle ====================================
         else: # NOT an outline
             count_textspan = 0 # Use in case num_textspan is set
             for subelem in draw_frame.iter():
                 if subelem.tag == TEXT_SPAN_TAG:
                     if count_textspan == num_textspan:
                         subelem.text = text
                     elif clear_all:
                         subelem.text = ''
                     count_textspan += 1
示例#11
0
 def set_textspan_text(self, frame_class='title', text='My Text', num_frame=0, 
                          num_textspan=0, clear_all=True ):
     
     if frame_class in self.draw_frameD:
         try:
             draw_frame = self.draw_frameD[frame_class][num_frame]
         except:
             draw_frame = self.draw_frameD[frame_class][-1]
             print('...ERROR... in Page.set_textspan_text, num_frame>len(frameL)')
         
         # ============================================ outline =========================================
         if frame_class == 'outline':
             text_box = draw_frame.find( force_to_tag('draw:text-box') )
             text_listL = draw_frame.findall( force_to_tag('draw:text-box/text:list') )
             
             max_indent = len( text_listL )-1
             
             if (text_box is not None) and text_listL:
                 #print('max_indent of outline = %i'%max_indent)
                 text_box.clear_children()
                 
                 # text comes in w/o formatting for outline.
                 outlineL = self.build_outline_list( text )
                 for n, sInp in outlineL:
                     n = min(n, max_indent)
                     text_list = deepcopy( text_listL[n] )
                     
                     #annn_new = self.presObj.get_next_a_style()
                     #text_list.set( force_to_tag('style:name'), annn_new )
                     
                     text_span = None
                     target_tag = force_to_tag('text:span')
                     for elem in text_list.iter():
                         if elem.tag == target_tag:
                             text_span = elem
                             break
                     
                     if text_span is not None:
                         text_span.text = sInp
                         text_box.append( text_list )
             
             
         # ============================================ title/subtitle ====================================
         else: # NOT an outline
             count_textspan = 0 # Use in case num_textspan is set
             for subelem in draw_frame.iter():
                 if subelem.tag == TEXT_SPAN_TAG:
                     if count_textspan == num_textspan:
                         subelem.text = text
                     elif clear_all:
                         subelem.text = ''
                     count_textspan += 1
示例#12
0
 def set_frame_svg_dimensions(self):
     
     svg_x = self.bbox.left_x
     svg_w = self.bbox.right_x - self.bbox.left_x
     svg_y = self.bbox.top_y
     svg_h = self.bbox.bottom_y - self.bbox.top_y
     
     self.my_draw_frame.set( force_to_tag('svg:x'), '%gin'%svg_x )
     self.my_draw_frame.set( force_to_tag('svg:width'), '%gin'%svg_w )
     self.my_draw_frame.set( force_to_tag('svg:y'), '%gin'%svg_y )
     self.my_draw_frame.set( force_to_tag('svg:height'), '%gin'%svg_h )
     
     self.my_draw_frame.set( force_to_tag('presentation:user-transformed'),"true" )
示例#13
0
    def set_frame_svg_dimensions(self):

        svg_x = self.bbox.left_x
        svg_w = self.bbox.right_x - self.bbox.left_x
        svg_y = self.bbox.top_y
        svg_h = self.bbox.bottom_y - self.bbox.top_y

        self.my_draw_frame.set(force_to_tag('svg:x'), '%gin' % svg_x)
        self.my_draw_frame.set(force_to_tag('svg:width'), '%gin' % svg_w)
        self.my_draw_frame.set(force_to_tag('svg:y'), '%gin' % svg_y)
        self.my_draw_frame.set(force_to_tag('svg:height'), '%gin' % svg_h)

        self.my_draw_frame.set(force_to_tag('presentation:user-transformed'),
                               "true")
示例#14
0
def NS(path_or_tag):
    """
    force into tag format like: '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}table' 
    
    (This is for backward compatibility... this is same as "force_to_tag".
    """
    return force_to_tag(path_or_tag)
示例#15
0
 def set_bullets(self, top_elem ):
     """
     I can't seem to find where my unicode bullet chars are getting messed up.
     For now, set all bullets to the bullet character.
     """
     
     bull_tag = force_to_tag( 'text:list-level-style-bullet' )
     for elem in top_elem.iter():
         if elem.tag == bull_tag:
             level = elem.get(force_to_tag('text:level'),'')
             if level:
                 c = elem.get(force_to_tag('text:bullet-char'), '')
                 
                 if len(c)>1:
                     #i = int( level )
                     bchar = u'\u2022' # BULLET_L[ i-1 ]  # u'\u25CF'
                     elem.set(force_to_tag('text:bullet-char'), bchar)
示例#16
0
    def set_bullets(self, top_elem):
        """
        I can't seem to find where my unicode bullet chars are getting messed up.
        For now, set all bullets to the bullet character.
        """

        bull_tag = force_to_tag('text:list-level-style-bullet')
        for elem in top_elem.iter():
            if elem.tag == bull_tag:
                level = elem.get(force_to_tag('text:level'), '')
                if level:
                    c = elem.get(force_to_tag('text:bullet-char'), '')

                    if len(c) > 1:
                        #i = int( level )
                        bchar = '\u2022'  # BULLET_L[ i-1 ]  # u'\u25CF'
                        elem.set(force_to_tag('text:bullet-char'), bchar)
示例#17
0
    def set_span_text_of_tag_w_attr(self, targ_tag, targ_attr_name, targ_attr_val,
                                         span_text=''):
        """
        dictionaries  hold style:name info (if init_all_annn_style8name)
        self.annn_style8nameD = {} # index=style:name ("a123"), value=elem
        self.style_refD = {} # index=xxxxx:style-name (e.g. "a123"), value=elem
        """
        targ_tag = force_to_tag( targ_tag )
        targ_attr_name = force_to_tag( targ_attr_name )
        span_tag = force_to_tag( 'text:span' )

        for elem in self.root.iter():
            # for example a 'draw:frame' with an attribute 'presentation:class' == "footer",
            if (elem.tag == targ_tag) and (elem.get(targ_attr_name,'') == targ_attr_val):
                
                # looking for a span element
                for sub_elem in elem.iter():
                    if sub_elem.tag == span_tag:
                        sub_elem.text = span_text
                        break
示例#18
0
def make_function_from_root( root, tmplt_obj, suffix='' ):
    """build python source to make the Elements from scratch"""
    
    suffix = suffix.replace(',','_')
    if suffix in func_quick_lookupD:
        n = 2
        while '%s_%i'%(suffix, n) in func_quick_lookupD:
            n += 1
        suffix = '%s_%i'%(suffix, n)
    
    func_name = python_def_from_tag(root.tag)
    if suffix:
        func_name = func_name + '_%s'%python_def_from_tag(suffix)
        
    # Used after code is generated
    func_quick_lookupD[suffix] = func_name    
    dname = root.get( force_to_tag('style:display-name'), '' )
    lname = root.get( force_to_tag('style:name'), '' )
    if dname and lname:
        layout_name_lookupD[dname] = lname
        display_name_lookupD[lname] = dname
    
    keyL = sorted( root.keys() )
    
    sL = ['def %s():'%(func_name, )]
    sL.append( '    ' )
    doc_str = 'Build Element %s'%force_to_short(root.tag)
    if suffix:
        doc_str = doc_str + ' for %s'%suffix
    sL.append( '''    """%s """'''%doc_str )
    sL.append( '    ' )
    
    sOut = tmplt_obj.elem_tostring(root, include_ns=False, use_linebreaks=True )
    sOut = fix_utf8( sOut )
    sL.append( '''    elem = build_element( """%s""" )'''%sOut )
    
    sL.append( '    ' )
    sL.append( '    return elem\n\n' )
    
    return '\n'.join(sL)
示例#19
0
def make_function_from_root(root, tmplt_obj, suffix=''):
    """build python source to make the Elements from scratch"""

    suffix = suffix.replace(',', '_')
    if suffix in func_quick_lookupD:
        n = 2
        while '%s_%i' % (suffix, n) in func_quick_lookupD:
            n += 1
        suffix = '%s_%i' % (suffix, n)

    func_name = python_def_from_tag(root.tag)
    if suffix:
        func_name = func_name + '_%s' % python_def_from_tag(suffix)

    # Used after code is generated
    func_quick_lookupD[suffix] = func_name
    dname = root.get(force_to_tag('style:display-name'), '')
    lname = root.get(force_to_tag('style:name'), '')
    if dname and lname:
        layout_name_lookupD[dname] = lname
        display_name_lookupD[lname] = dname

    keyL = sorted(root.keys())

    sL = ['def %s():' % (func_name, )]
    sL.append('    ')
    doc_str = 'Build Element %s' % force_to_short(root.tag)
    if suffix:
        doc_str = doc_str + ' for %s' % suffix
    sL.append('''    """%s """''' % doc_str)
    sL.append('    ')

    sOut = tmplt_obj.elem_tostring(root, include_ns=False, use_linebreaks=True)
    sOut = fix_utf8(sOut)
    sL.append('''    elem = build_element( """%s""" )''' % sOut)

    sL.append('    ')
    sL.append('    return elem\n\n')

    return '\n'.join(sL)
示例#20
0
    def swap_svg_y_of_objects_and_outline(self):
        """
        Used to modify "Title and 2 Content over Text" page to put text on top
        """
        img_class = ''
        if 'object' in self.draw_frameD:
            img_class = 'object'
        if 'graphic' in self.draw_frameD:
            img_class = 'graphic'
        
        if img_class and ('outline' in self.draw_frameD):
            
            yobj = self.draw_frameD[img_class][0].get( force_to_tag('svg:y'), '' )
            yout = self.draw_frameD['outline'][0].get( force_to_tag('svg:y'), '' )
            
            for draw_frame in self.draw_frameD[img_class]:
                draw_frame.set(force_to_tag('svg:y'), yout)
            
            for draw_frame in self.draw_frameD['outline']:
                draw_frame.set(force_to_tag('svg:y'), yobj)

            # Need to tell app that things have changed from master
            draw_frame.set( force_to_tag('presentation:user-transformed'),"true" )
            
            # ----------- need to rebuild FrameDim and Blockade objects -------------
            # Build FrameDim objects for each draw:frame object
            #self.frame_dimL = []
            #for draw_frame in self.draw_frameL:
            #    self.frame_dimL.append( FrameDim(self, draw_frame) )
            
            # Need to recalc Blockade objects
            #for frame_dim in self.frame_dimL:
            #    frame_dim.calc_local_blockades()
            #self.build_dict_of_unique_blockades()

        else:
            print('...ERROR... could NOT swap objects and outline svg:y values')
            print('..........',self.draw_frameD.keys())
示例#21
0
    def swap_svg_y_of_objects_and_outline(self):
        """
        Used to modify "Title and 2 Content over Text" page to put text on top
        """
        img_class = ''
        if 'object' in self.draw_frameD:
            img_class = 'object'
        if 'graphic' in self.draw_frameD:
            img_class = 'graphic'
        
        if img_class and ('outline' in self.draw_frameD):
            
            yobj = self.draw_frameD[img_class][0].get( force_to_tag('svg:y'), '' )
            yout = self.draw_frameD['outline'][0].get( force_to_tag('svg:y'), '' )
            
            for draw_frame in self.draw_frameD[img_class]:
                draw_frame.set(force_to_tag('svg:y'), yout)
            
            for draw_frame in self.draw_frameD['outline']:
                draw_frame.set(force_to_tag('svg:y'), yobj)

            # Need to tell app that things have changed from master
            draw_frame.set( force_to_tag('presentation:user-transformed'),"true" )
            
            # ----------- need to rebuild FrameDim and Blockade objects -------------
            # Build FrameDim objects for each draw:frame object
            #self.frame_dimL = []
            #for draw_frame in self.draw_frameL:
            #    self.frame_dimL.append( FrameDim(self, draw_frame) )
            
            # Need to recalc Blockade objects
            #for frame_dim in self.frame_dimL:
            #    frame_dim.calc_local_blockades()
            #self.build_dict_of_unique_blockades()

        else:
            print('...ERROR... could NOT swap objects and outline svg:y values')
            print('..........',list(self.draw_frameD.keys()))
示例#22
0
    def __init__(self, my_page, my_draw_frame):
        """
        Build blockades and bbox
        """
        self.my_page = my_page
        self.my_draw_frame = my_draw_frame
        
        self.my_frame_class = my_draw_frame.get( PRESENTATION_CLASS_ATTR, '' )
        
        # Start out with blockades the same as full page
        self.left_blockade   = deepcopy( my_page.left_blockade )
        self.right_blockade  = deepcopy( my_page.right_blockade )
        self.top_blockade    = deepcopy( my_page.top_blockade )
        self.bottom_blockade = deepcopy( my_page.bottom_blockade )

        svg_x = force_svg_dim_to_float( my_draw_frame.get( force_to_tag('svg:x'), '' ) )
        svg_y = force_svg_dim_to_float( my_draw_frame.get( force_to_tag('svg:y'), '' ) )
        svg_w = force_svg_dim_to_float( my_draw_frame.get( force_to_tag('svg:width'), '' ) )
        svg_h = force_svg_dim_to_float( my_draw_frame.get( force_to_tag('svg:height'), '' ) )
        
        self.bbox = BBox( svg_x, svg_x + svg_w, svg_y, svg_y + svg_h )
        
        self.make_side_segments() # for current state of BBox
示例#23
0
    def set_span_text_of_tag_w_attr(self,
                                    targ_tag,
                                    targ_attr_name,
                                    targ_attr_val,
                                    span_text=''):
        """
        dictionaries  hold style:name info (if init_all_annn_style8name)
        self.annn_style8nameD = {} # index=style:name ("a123"), value=elem
        self.style_refD = {} # index=xxxxx:style-name (e.g. "a123"), value=elem
        """
        targ_tag = force_to_tag(targ_tag)
        targ_attr_name = force_to_tag(targ_attr_name)
        span_tag = force_to_tag('text:span')

        for elem in self.root.iter():
            # for example a 'draw:frame' with an attribute 'presentation:class' == "footer",
            if (elem.tag == targ_tag) and (elem.get(targ_attr_name, '')
                                           == targ_attr_val):

                # looking for a span element
                for sub_elem in elem.iter():
                    if sub_elem.tag == span_tag:
                        sub_elem.text = span_text
                        break
def get_final_presentation_elem():

    return ET.Element(force_to_tag("presentation:settings"))
def get_final_presentation_elem():

    return ET.Element(force_to_tag('presentation:settings'))
示例#26
0
def add_text_box( presObj, text_or_list='Test Message', 
                    text_font_colors='black #333333',
                    x=8.0, y=2.0):
    """
    text_font_colors can be a list of colors or a single string with space-seperated colors
    (e.g. "black #666666" or ["black", "#666666"])
    """
    if not presObj.new_content_pageL:
        print('...WARNING... No Last Page for TextBox:', text_or_list)
        return
    
    last_page = presObj.new_content_pageL[-1] # Page object 
    
    # Build a color list (colorL)
    # If not already in list form, make a list
    if type(text_font_colors) != type(['r','b']):
        # Create a list of colors
        colorL = text_font_colors.split(' ') # <- make a list
    else:
        colorL = text_font_colors # <- already a list
    # make the colors valid
    colorL = [ getValidHexStr(c,'#000000') for c in colorL ]    
    
    # if there's a problem with the list, make a default list
    if not colorL:
        colorL = ['#000000']
    
    # get new style names (e.g. "a123")
    a_frame = presObj.get_next_a_style()

    # Make new Element objects and style Element objects
    s = TBOX_DRAW_FRAME.replace('svg:x="5.75in" svg:y="3in"','svg:x="%sin" svg:y="%sin"'%(x,y))
    draw_frame = TemplateXML_File( s.replace('"a343"', '"%s"'%a_frame) ).root
    text_box = draw_frame.find( force_to_tag('draw:text-box') )
    
    draw_frame_style = TemplateXML_File( TBOX_DRAW_FRAME_STYLE.replace('"a343"', '"%s"'%a_frame) ).root
    
    # get all the lines in the TextBox
    textL = build_text_list(text_or_list)
    annn_styleElemL = [(a_frame, draw_frame_style)]
    
    for itext, text in enumerate(textL):
        
        hex_col_str = colorL[ itext % len(colorL) ]
        a_p = presObj.get_next_a_style()
        a_span = presObj.get_next_a_style()
    
        p_span_elem = TemplateXML_File( TBOX_TEXT_P_SPAN.replace('"a337"', '"%s"'%a_p).replace('"a336"', '"%s"'%a_span) ).root
        span_elem = p_span_elem.getchildren()[0]
        span_elem.text = text
        
        s = TBOX_TEXT_P_STYLE.replace( 'fo:color="#000000"', 'fo:color="%s"'%hex_col_str )
        p_style =  TemplateXML_File( s.replace('"a337"', '"%s"'%a_p) ).root
        
        s = TBOX_TEXT_SPAN_STYLE.replace( 'fo:color="#000000"', 'fo:color="%s"'%hex_col_str )
        span_style =  TemplateXML_File( s.replace('"a336"', '"%s"'%a_span) ).root
        
        annn_styleElemL.append(  (a_p, p_style) )
        annn_styleElemL.append( (a_span, span_style) )
        text_box.append( p_span_elem )
    
    # put the new style descriptions and elements into the Presentation object.
    for a_new, style_elem in annn_styleElemL:
        presObj.new_content_styleL.append( style_elem )
        presObj.new_content_styleD[ a_new ] = style_elem
                    
    
    last_page.draw_page.append( draw_frame )
示例#27
0
        fOut.write('\n\nmaster_page_name_lookupD = {}')

        fOut.write(
            '\n\n# Use layout_page_name_lookupD for access layout page names')
        fOut.write(
            '\n# index=layout name (e.g. "Master1-Layout24-tbl-Title-and-Table"), value=master name (e.g. "Master1-PPL24")'
        )
        fOut.write('\n\nlayout_page_name_lookupD = {}')

        fOut.write('\n\n')

        # do style:presentation-page-layout

        for style in odp.content_body_presentation.getchildren():
            layout_name = style.get(
                force_to_tag('presentation:presentation-page-layout-name'),
                'nofam')
            master_name = style.get(force_to_tag('draw:master-page-name'),
                                    'noname')

            if layout_name == 'nofam':
                suffix = force_to_short(style.tag)
            else:
                suffix = layout_name
                master_page_name_lookupD[layout_name] = master_name
                layout_page_name_lookupD[master_name] = layout_name

            fOut.write(
                make_function_from_root(style,
                                        odp.content_xml_obj,
                                        suffix=suffix).encode('utf-8'))
示例#28
0
        got_attrib = True
        for atag, val in list(D.items()):
            if elem.get(atag, None) != val:
                got_attrib = False
        if got_attrib:
            returnL.append((elem, i_match))

    # If nothing matches, return None
    if len(returnL) == 0:
        return None, None

    # Can return entire list or nth matching Element
    if return_list:
        return returnL  # a list of tuples (elem, i_match)
    else:
        # an extra line just to remind me of the tuple returned
        elem, i_match = returnL[nth_match]
        return elem, i_match


if __name__ == "__main__":

    print(NS('draw:page'))
    print(NS('draw:page/draw:frame'))
    print('............................')
    print(force_to_tag('draw:page'))
    print(force_to_tag('draw:page/draw:frame'))

    print('............................')
    print(NS_attrib({'draw:id': 'id1'}))
    s = s.replace(' ',' %s '%XMLNS_STR, 1) # First space ONLY
    return TemplateXML_File( s ).root
                
''' )
        fOut.write('\n\n# Use func_quick_lookupD for access to function calls')
        fOut.write( '\n\nfunc_quick_lookupD = {} # index=suffix name, value=function name\n' )
        
        fOut.write('\n\n# Use content_style_name_lookupD for access to function calls')
        fOut.write( '\n\ncontent_style_name_lookupD = {} # index=style name (e.g. "a123"), value=function name\n' )
        
        fOut.write('\n\n')
        
        # do style:presentation-page-layout
        
        for style in odp.content_auto_styles.getchildren():
            suffix = style.get( force_to_tag('style:family'), 'nofam' ) 
            if suffix == 'nofam':
                suffix = style.get( force_to_tag('style:name'), 'noname' )
            else:
                suffix = suffix + '_' + style.get( force_to_tag('style:name'), 'noname' )
                
            fOut.write( make_function_from_root( style, odp.content_xml_obj, suffix=suffix ).encode('utf-8') )
            
            print( odp.content_xml_obj.elem_tostring(style) )
            print('\n')


        fOut.write('\n\n# Set values in func_quick_lookupD\n')
        keyL = sorted( func_quick_lookupD.keys() )
        for key in keyL:
            fOut.write( 'func_quick_lookupD["%s"] = %s\n'%(key, func_quick_lookupD[key]) )
示例#30
0
 def set_page_number(self, ipage):
     
     self.draw_page.set( force_to_tag('draw:name'), 'Slide%i'%ipage )
     
     self.draw_page.set( force_to_tag( 'draw:id' ), 'Slide-%i'%ipage )
示例#31
0
def add_text_box( presObj, text_or_list='Test Message', 
                    text_font_colors='black #333333',
                    x=8.0, y=2.0):
    """
    text_font_colors can be a list of colors or a single string with space-seperated colors
    (e.g. "black #666666" or ["black", "#666666"])
    """
    if not presObj.new_content_pageL:
        print('...WARNING... No Last Page for TextBox:', text_or_list)
        return
    
    last_page = presObj.new_content_pageL[-1] # Page object 
    
    # Build a color list (colorL)
    # If not already in list form, make a list
    if type(text_font_colors) != type(['r','b']):
        # Create a list of colors
        colorL = text_font_colors.split(' ') # <- make a list
    else:
        colorL = text_font_colors # <- already a list
    # make the colors valid
    colorL = [ getValidHexStr(c,'#000000') for c in colorL ]    
    
    # if there's a problem with the list, make a default list
    if not colorL:
        colorL = ['#000000']
    
    # get new style names (e.g. "a123")
    a_frame = presObj.get_next_a_style()

    # Make new Element objects and style Element objects
    s = TBOX_DRAW_FRAME.replace('svg:x="5.75in" svg:y="3in"','svg:x="%sin" svg:y="%sin"'%(x,y))
    draw_frame = TemplateXML_File( s.replace('"a343"', '"%s"'%a_frame) ).root
    text_box = draw_frame.find( force_to_tag('draw:text-box') )
    
    draw_frame_style = TemplateXML_File( TBOX_DRAW_FRAME_STYLE.replace('"a343"', '"%s"'%a_frame) ).root
    
    # get all the lines in the TextBox
    textL = build_text_list(text_or_list)
    annn_styleElemL = [(a_frame, draw_frame_style)]
    
    for itext, text in enumerate(textL):
        
        hex_col_str = colorL[ itext % len(colorL) ]
        a_p = presObj.get_next_a_style()
        a_span = presObj.get_next_a_style()
    
        p_span_elem = TemplateXML_File( TBOX_TEXT_P_SPAN.replace('"a337"', '"%s"'%a_p).replace('"a336"', '"%s"'%a_span) ).root
        span_elem = p_span_elem.getchildren()[0]
        span_elem.text = text
        
        s = TBOX_TEXT_P_STYLE.replace( 'fo:color="#000000"', 'fo:color="%s"'%hex_col_str )
        p_style =  TemplateXML_File( s.replace('"a337"', '"%s"'%a_p) ).root
        
        s = TBOX_TEXT_SPAN_STYLE.replace( 'fo:color="#000000"', 'fo:color="%s"'%hex_col_str )
        span_style =  TemplateXML_File( s.replace('"a336"', '"%s"'%a_span) ).root
        
        annn_styleElemL.append(  (a_p, p_style) )
        annn_styleElemL.append( (a_span, span_style) )
        text_box.append( p_span_elem )
    
    # put the new style descriptions and elements into the Presentation object.
    for a_new, style_elem in annn_styleElemL:
        presObj.new_content_styleL.append( style_elem )
        presObj.new_content_styleD[ a_new ] = style_elem
                    
    
    last_page.draw_page.append( draw_frame )
示例#32
0
import odpslides.solidbg.styles_auto_styles
import odpslides.solidbg.styles_master_pages

import odpslides.image.content_auto_styles
import odpslides.image.content_body_presentation
import odpslides.image.page_layouts
import odpslides.image.styles_auto_styles
import odpslides.image.styles_master_pages

import odpslides.grad.content_auto_styles
import odpslides.grad.content_body_presentation
import odpslides.grad.page_layouts
import odpslides.grad.styles_auto_styles
import odpslides.grad.styles_master_pages

DRAW_FRAME_TAG = force_to_tag( 'draw:frame' )
TEXT_SPAN_TAG =  force_to_tag( 'text:span' )
TEXT_STYLE_NAME_ATTR = force_to_tag( 'text:style-name' )
DRAW_STYLE_NAME_ATTR = force_to_tag( 'draw:style-name' )
DRAW_FILL_COLOR_ATTR = force_to_tag( 'draw:fill-color' )
DRAW_ID_ATTR = force_to_tag( 'draw:id' )
DRAW_PAGE_TAG = force_to_tag( 'draw:page' )
FONT_COLOR_ATTR = force_to_tag( 'fo:color' )
PRESENTATION_CLASS_ATTR = force_to_tag( 'presentation:class' )
PRESENTATION_TRANSITION_TYPE_ATTR = force_to_tag( 'presentation:transition-type' )
PRESENTATION_TRANSITION_SPEED_ATTR = force_to_tag( 'presentation:transition-speed' )
STYLE_STYLE_TAG = force_to_tag( 'style:style' )
PRESENTATION_BG_VISIBLE_ATTR = force_to_tag( 'presentation:background-visible' )
PRESENTATION_BG_OBJ_VISIBLE_ATTR = force_to_tag('presentation:background-objects-visible' )

STYLE_DRAWING_PAGE_PROPS_TAG = force_to_tag( 'style:drawing-page-properties' )
示例#33
0
# Support Python 2 and 3

import time
import sys
from copy import deepcopy

from odpslides.namespace import XMLNS_STR, force_to_short, force_to_tag
from odpslides.color_utils import getValidHexStr

DRAW_PAGE_TAG = force_to_tag('draw:page')


class ContentXML(object):
    """
    ContentXML wraps the content.xml internal file of the reference odp file
    """
    def __init__(self, presObj, odp_ref):
        """
        presObj is the Presentation object
        
        odp_ref is the odp file opened by the Presentation object
        """

        self.presObj = presObj
        self.odp_ref = odp_ref

        self.make_clean_copy()

    def make_clean_copy(self):
        # Make a copy of the original content.xml Elements
        self.content_tmplt = deepcopy(self.odp_ref.content_xml_obj)
示例#34
0
    def init_all_annn_style8name(self):
        
        STYLE_NAME_ATTR = force_to_tag( 'style:name' )
        DRAW_ID_ATTR = force_to_tag( 'draw:id' )
        
        # reset in case called twice
        self.annn_style8nameD = {} # index=style:name ("a123"), value=elem
        self.style_refD = {} # index=xxxxx:style-name (e.g. "a123"), value=elem
        self.id_draw8idD = {} # index=draw:id (e.g. "id123"), value=elem

        for elem in self.root.iter():
            att_val = elem.get(STYLE_NAME_ATTR, '')
            if att_val.startswith('a'):
                if att_val in self.annn_style8nameD:
                    print('...ERROR... More than one definition for:', att_val)
                    self.annn_style8nameD[ att_val ] = [ self.annn_style8nameD[ att_val ] ]
                    self.annn_style8nameD[ att_val ].append( elem )
                else:
                    self.annn_style8nameD[ att_val ] = elem

            for aname, aval in elem.items():
                if aname.endswith( '}style-name' ):
                    if aval in self.style_refD:
                        self.style_refD[ aval ] = [ self.style_refD[ aval ] ]
                        self.style_refD[ aval ].append( elem )
                    else:
                        self.style_refD[ aval ] = elem
                        
            att_val = elem.get(DRAW_ID_ATTR, '')
            if att_val.startswith('id'):
                if att_val in self.id_draw8idD:
                    print('...ERROR... More than one definition for:', att_val)
                    self.id_draw8idD[ att_val ] = [ self.id_draw8idD[ att_val ] ]
                    self.id_draw8idD[ att_val ].append( elem )
                else:
                    self.id_draw8idD[ att_val ] = elem
                

        self.max_annn_def = -1
        self.min_annn_def = 9999999999
        for annn in self.annn_style8nameD.keys():
            self.max_annn_def = max( self.max_annn_def, int(annn[1:]) )
            self.min_annn_def = min( self.min_annn_def, int(annn[1:]) )
        #print('min_annn_def self.annn_style8nameD = ', self.min_annn_def)
        #print('max_annn_def self.annn_style8nameD = ', self.max_annn_def)


        self.max_annn_used = -1
        self.min_annn_used = 9999999999
        for annn in self.style_refD.keys():
            self.max_annn_used = max( self.max_annn_used, int(annn[1:]) )
            self.min_annn_used = min( self.min_annn_used, int(annn[1:]) )
        #print('min_annn_used self.annn_style8nameD = ', self.min_annn_used)
        #print('max_annn_used self.annn_style8nameD = ', self.max_annn_used)


        self.max_idnnn_def = -1
        self.min_idnnn_def = 9999999999
        for idnnn in self.id_draw8idD.keys():
            self.max_idnnn_def = max( self.max_idnnn_def, int(idnnn[2:]) )
            self.min_idnnn_def = min( self.min_idnnn_def, int(idnnn[2:]) )
示例#35
0
    s = s.replace(' ',' %s '%XMLNS_STR, 1) # First space ONLY
    return TemplateXML_File( s ).root
                
''')
        fOut.write('\n\n# Use func_quick_lookupD for access to function calls')
        fOut.write(
            '\n\nfunc_quick_lookupD = {} # index=display name, value=function name\n'
        )

        fOut.write('layout_name_lookupD = {}\n')
        fOut.write('display_name_lookupD = {}\n')
        fOut.write('\n\n')

        # do style:presentation-page-layout
        page_layoutL = odp.office_styles_elem.findall(
            force_to_tag('style:presentation-page-layout'))
        for layout in page_layoutL:
            fOut.write(
                make_function_from_root(
                    layout,
                    odp.styles_xml_obj,
                    suffix=layout.get(force_to_tag('style:display-name'))))

        # do style:default-style
        page_layoutL = odp.office_styles_elem.findall(
            force_to_tag('style:default-style'))
        for layout in page_layoutL:
            fOut.write(
                make_function_from_root(layout,
                                        odp.styles_xml_obj,
                                        suffix=layout.get(
示例#36
0
        fOut.write('\n\n# Use master_page_name_lookupD for access to master page names')
        fOut.write('\n# index=layout name (e.g. "Master1-PPL24"), value=master name (e.g. "Master1-Layout24-tbl-Title-and-Table")')
        fOut.write( '\n\nmaster_page_name_lookupD = {}' )
        
        
        
        fOut.write('\n\n# Use layout_page_name_lookupD for access layout page names')
        fOut.write('\n# index=layout name (e.g. "Master1-Layout24-tbl-Title-and-Table"), value=master name (e.g. "Master1-PPL24")')
        fOut.write( '\n\nlayout_page_name_lookupD = {}' )
        
        fOut.write('\n\n')
        
        # do style:presentation-page-layout
        
        for style in odp.content_body_presentation.getchildren():
            layout_name = style.get( force_to_tag('presentation:presentation-page-layout-name'), 'nofam' ) 
            master_name = style.get( force_to_tag('draw:master-page-name'), 'noname' )
            
            if layout_name == 'nofam':
                suffix = force_to_short(style.tag)
            else:
                suffix = layout_name
                master_page_name_lookupD[ layout_name ] = master_name
                layout_page_name_lookupD[ master_name ] = layout_name
                
            fOut.write( make_function_from_root( style, odp.content_xml_obj, suffix=suffix ).encode('utf-8') )


        fOut.write('\n\n# Set values in func_quick_lookupD\n')
        keyL = sorted( func_quick_lookupD.keys() )
        for key in keyL:
示例#37
0
def maybe_add_func_name_to_a_dict( elem, func_name ):
    target = force_to_tag( 'style:name' )
    value = elem.get(target, None)
    if value is not None:
        styles_style_name_lookupD[value] = func_name
示例#38
0
# Support Python 2 and 3

import os
import sys
from copy import deepcopy

from odpslides.namespace import XMLNS_STR, force_to_short, force_to_tag
from odpslides.segments import segment_intersect, Point, BBox
from odpslides.blockade import Blockade

# Assume that all reference slides conform to "pageLayout3" (10in x 7.5in)
PAGE_WIDTH = 10.0  # inches
PAGE_HEIGHT = 7.5  # inches
FOOTER_HEIGHT = 6.95139  # inches

PRESENTATION_CLASS_ATTR = force_to_tag('presentation:class')


def force_svg_dim_to_float(s):
    """Usually gets a value like:"1.23456in" (i.e. inches) """
    try:
        val = float(s[:-2])
    except:
        val = 0.0
        print('...ERROR... in force_svg_dim_to_float. Inches value = "%s"' % s)
    return val


class FrameDim(object):
    """
    The dimensions of a draw:frame object.
def maybe_add_func_name_to_a_dict( elem, func_name ):
    target = force_to_tag( 'style:name' )
    value = elem.get(target, None)
    if value is not None:
        content_style_name_lookupD[value] = func_name
示例#40
0
import odpslides.solidbg.styles_auto_styles
import odpslides.solidbg.styles_master_pages

import odpslides.image.content_auto_styles
import odpslides.image.content_body_presentation
import odpslides.image.page_layouts
import odpslides.image.styles_auto_styles
import odpslides.image.styles_master_pages

import odpslides.grad.content_auto_styles
import odpslides.grad.content_body_presentation
import odpslides.grad.page_layouts
import odpslides.grad.styles_auto_styles
import odpslides.grad.styles_master_pages

DRAW_FRAME_TAG = force_to_tag( 'draw:frame' )
TEXT_SPAN_TAG =  force_to_tag( 'text:span' )
TEXT_STYLE_NAME_ATTR = force_to_tag( 'text:style-name' )
DRAW_STYLE_NAME_ATTR = force_to_tag( 'draw:style-name' )
DRAW_FILL_COLOR_ATTR = force_to_tag( 'draw:fill-color' )
DRAW_ID_ATTR = force_to_tag( 'draw:id' )
DRAW_PAGE_TAG = force_to_tag( 'draw:page' )
FONT_COLOR_ATTR = force_to_tag( 'fo:color' )
PRESENTATION_CLASS_ATTR = force_to_tag( 'presentation:class' )
PRESENTATION_TRANSITION_TYPE_ATTR = force_to_tag( 'presentation:transition-type' )
PRESENTATION_TRANSITION_SPEED_ATTR = force_to_tag( 'presentation:transition-speed' )
STYLE_STYLE_TAG = force_to_tag( 'style:style' )
PRESENTATION_BG_VISIBLE_ATTR = force_to_tag( 'presentation:background-visible' )
PRESENTATION_BG_OBJ_VISIBLE_ATTR = force_to_tag('presentation:background-objects-visible' )

STYLE_DRAWING_PAGE_PROPS_TAG = force_to_tag( 'style:drawing-page-properties' )
示例#41
0
# Support Python 2 and 3
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import print_function

import time
import sys
from copy import deepcopy

from odpslides.namespace import XMLNS_STR, force_to_short, force_to_tag
from odpslides.color_utils import getValidHexStr

DRAW_PAGE_TAG = force_to_tag( 'draw:page' )

class ContentXML(object):
    """
    ContentXML wraps the content.xml internal file of the reference odp file
    """
    
    def __init__(self, presObj, odp_ref):
        """
        presObj is the Presentation object
        
        odp_ref is the odp file opened by the Presentation object
        """
        
        self.presObj = presObj
        self.odp_ref = odp_ref
        
        self.make_clean_copy()
        
示例#42
0
    return TemplateXML_File( s ).root
                
                
''' )
        fOut.write('\n\n# Use func_quick_lookupD for access to function calls')
        fOut.write( '\n\nfunc_quick_lookupD = {} # index=suffix name, value=function name\n' )
        
        fOut.write('\n\n# Use styles_style_name_lookupD for access to function calls')
        fOut.write( '\n\nstyles_style_name_lookupD = {} # index=style name (e.g. "a123"), value=function name\n' )
        
        fOut.write('\n\n')
        
        # do style:presentation-page-layout
        
        for style in odp.office_automatic_styles_elem.getchildren():
            suffix = style.get( force_to_tag('style:family'), 'nofam' ) 
            if suffix == 'nofam':
                suffix = style.get( force_to_tag('style:name'), 'noname' )
            else:
                suffix = suffix + '_' + style.get( force_to_tag('style:name'), 'noname' )
                
            fOut.write( make_function_from_root( style, odp.styles_xml_obj, suffix=suffix ).encode('utf-8') )


        fOut.write('\n\n# Set values in func_quick_lookupD\n')
        keyL = sorted( func_quick_lookupD.keys() )
        for key in keyL:
            fOut.write( 'func_quick_lookupD["%s"] = %s\n'%(key, func_quick_lookupD[key]) )

        fOut.write('\n\n')
        
示例#43
0
    def init_all_annn_style8name(self):

        STYLE_NAME_ATTR = force_to_tag('style:name')
        DRAW_ID_ATTR = force_to_tag('draw:id')

        # reset in case called twice
        self.annn_style8nameD = {}  # index=style:name ("a123"), value=elem
        self.style_refD = {
        }  # index=xxxxx:style-name (e.g. "a123"), value=elem
        self.id_draw8idD = {}  # index=draw:id (e.g. "id123"), value=elem

        for elem in self.root.iter():
            att_val = elem.get(STYLE_NAME_ATTR, '')
            if att_val.startswith('a'):
                if att_val in self.annn_style8nameD:
                    print('...ERROR... More than one definition for:', att_val)
                    self.annn_style8nameD[att_val] = [
                        self.annn_style8nameD[att_val]
                    ]
                    self.annn_style8nameD[att_val].append(elem)
                else:
                    self.annn_style8nameD[att_val] = elem

            for aname, aval in list(elem.items()):
                if aname.endswith('}style-name'):
                    if aval in self.style_refD:
                        self.style_refD[aval] = [self.style_refD[aval]]
                        self.style_refD[aval].append(elem)
                    else:
                        self.style_refD[aval] = elem

            att_val = elem.get(DRAW_ID_ATTR, '')
            if att_val.startswith('id'):
                if att_val in self.id_draw8idD:
                    print('...ERROR... More than one definition for:', att_val)
                    self.id_draw8idD[att_val] = [self.id_draw8idD[att_val]]
                    self.id_draw8idD[att_val].append(elem)
                else:
                    self.id_draw8idD[att_val] = elem

        self.max_annn_def = -1
        self.min_annn_def = 9999999999
        for annn in list(self.annn_style8nameD.keys()):
            self.max_annn_def = max(self.max_annn_def, int(annn[1:]))
            self.min_annn_def = min(self.min_annn_def, int(annn[1:]))
        #print('min_annn_def self.annn_style8nameD = ', self.min_annn_def)
        #print('max_annn_def self.annn_style8nameD = ', self.max_annn_def)

        self.max_annn_used = -1
        self.min_annn_used = 9999999999
        for annn in list(self.style_refD.keys()):
            self.max_annn_used = max(self.max_annn_used, int(annn[1:]))
            self.min_annn_used = min(self.min_annn_used, int(annn[1:]))
        #print('min_annn_used self.annn_style8nameD = ', self.min_annn_used)
        #print('max_annn_used self.annn_style8nameD = ', self.max_annn_used)

        self.max_idnnn_def = -1
        self.min_idnnn_def = 9999999999
        for idnnn in list(self.id_draw8idD.keys()):
            self.max_idnnn_def = max(self.max_idnnn_def, int(idnnn[2:]))
            self.min_idnnn_def = min(self.min_idnnn_def, int(idnnn[2:]))
示例#44
0
 def set_page_number(self, ipage):
     
     self.draw_page.set( force_to_tag('draw:name'), 'Slide%i'%ipage )
     
     self.draw_page.set( force_to_tag( 'draw:id' ), 'Slide-%i'%ipage )
示例#45
0
# Support Python 2 and 3




from odpslides.color_utils import getValidHexStr
from odpslides.namespace import XMLNS_STR, force_to_short, force_to_tag

DRAW_FRAME_TAG = force_to_tag( 'draw:frame' )
TEXT_SPAN_TAG =  force_to_tag( 'text:span' )
TEXT_STYLE_NAME_ATTR = force_to_tag( 'text:style-name' )
FONT_COLOR_ATTR = force_to_tag( 'fo:color' )
PRESENTATION_CLASS_ATTR = force_to_tag( 'presentation:class' )

def set_drawframe_font_color( presObj, draw_page, frame_class='title', font_color='black' ):
    """
    Set the fo:color in all the style elements of the frame
    
    """

    hex_col_str = getValidHexStr( font_color, "#000000") # default to black
    
    for elem in draw_page.iter():
        if elem.tag == DRAW_FRAME_TAG:
            if elem.get( PRESENTATION_CLASS_ATTR, '' ) == frame_class:
                # Now we are in proper "title", "subtitle", etc.
                for subelem in elem.iter():
                    if subelem.tag == TEXT_SPAN_TAG:
                        aNNN = subelem.get( TEXT_STYLE_NAME_ATTR, '' )
                        a_int = int( aNNN[1:] )
                        if a_int >= len(presObj.new_content_styleL):
示例#46
0
def build_element( s ):
    """Add namespace to string and use TemplateXML_File to make Element"""
    s = s.replace(' ',' %s '%XMLNS_STR, 1) # First space ONLY
    return TemplateXML_File( s ).root
                
''' )
        fOut.write('\n\n# Use func_quick_lookupD for access to function calls')
        fOut.write( '\n\nfunc_quick_lookupD = {} # index=display name, value=function name\n' )
        
        fOut.write( 'layout_name_lookupD = {}\n' )
        fOut.write( 'display_name_lookupD = {}\n' )
        fOut.write('\n\n')
        
        # do style:presentation-page-layout
        page_layoutL = odp.office_styles_elem.findall( force_to_tag('style:presentation-page-layout') )
        for layout in page_layoutL:
            fOut.write( make_function_from_root( layout,  odp.styles_xml_obj,
                    suffix=layout.get( force_to_tag('style:display-name') ) ) )
        
        # do style:default-style
        page_layoutL = odp.office_styles_elem.findall( force_to_tag('style:default-style') )
        for layout in page_layoutL:
            fOut.write( make_function_from_root( layout, odp.styles_xml_obj,
                    suffix=layout.get( force_to_tag('style:family') ) ) )

        
        # do draw:gradient
        page_styleL = odp.office_styles_elem.findall( force_to_tag('draw:gradient') )
        for style in page_styleL:
            fOut.write( make_function_from_root( style, odp.styles_xml_obj, suffix='' ) )
示例#47
0
# Support Python 2 and 3
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import print_function

from odpslides.color_utils import getValidHexStr
from odpslides.namespace import XMLNS_STR, force_to_short, force_to_tag

DRAW_FRAME_TAG = force_to_tag( 'draw:frame' )
TEXT_SPAN_TAG =  force_to_tag( 'text:span' )
TEXT_STYLE_NAME_ATTR = force_to_tag( 'text:style-name' )
FONT_COLOR_ATTR = force_to_tag( 'fo:color' )
PRESENTATION_CLASS_ATTR = force_to_tag( 'presentation:class' )

def set_drawframe_font_color( presObj, draw_page, frame_class='title', font_color='black' ):
    """
    Set the fo:color in all the style elements of the frame
    
    """

    hex_col_str = getValidHexStr( font_color, "#000000") # default to black
    
    for elem in draw_page.iter():
        if elem.tag == DRAW_FRAME_TAG:
            if elem.get( PRESENTATION_CLASS_ATTR, '' ) == frame_class:
                # Now we are in proper "title", "subtitle", etc.
                for subelem in elem.iter():
                    if subelem.tag == TEXT_SPAN_TAG:
                        aNNN = subelem.get( TEXT_STYLE_NAME_ATTR, '' )
                        a_int = int( aNNN[1:] )
                        if a_int >= len(presObj.new_content_styleL):
示例#48
0
from __future__ import print_function

import os
import sys
from copy import deepcopy

from odpslides.namespace import XMLNS_STR, force_to_short, force_to_tag
from odpslides.segments import segment_intersect, Point, BBox
from odpslides.blockade import Blockade

# Assume that all reference slides conform to "pageLayout3" (10in x 7.5in)
PAGE_WIDTH = 10.0 # inches
PAGE_HEIGHT = 7.5 # inches
FOOTER_HEIGHT = 6.95139 # inches

PRESENTATION_CLASS_ATTR = force_to_tag( 'presentation:class' )

def force_svg_dim_to_float( s ):
    """Usually gets a value like:"1.23456in" (i.e. inches) """
    try:
        val = float( s[:-2] )
    except:
        val = 0.0
        print('...ERROR... in force_svg_dim_to_float. Inches value = "%s"'%s)
    return val

class FrameDim(object):
    """
    The dimensions of a draw:frame object.
    Has four Blockade objects to limit translation and a bounding box to define location.
    """