Example #1
0
    def flatten(self, data=None, internal=False):
        '''
            Convert image to a cylindrical projection and return
            the converted data.
        '''
        
        if not data:
            data = self.filedata
        

        if not self.idata:
            data = re.sub( self.r_coords, self.expand_values, data )
            fixer = tagFix()
            data = fixer.tagfix('p',
                               data,
                               matchfunc=self.fix_pin,
                               regex=self.r_pin)
        else:
            print "  Skipping flatten step as unnecessary."

        if not internal:
            data = self.viewport_set( data )
            if self.pins:
                data = re.sub( '</svg>', self.get_pins() + '</svg>', data )
            self.write_imagemap( data, flat_output=True )
        return data
Example #2
0
 def isolate_contiguous_country(self, txt):
     fixer = tagFix()
     txt = fixer.tagfix('path', txt,
                         matchfunc=self.delete_tag,
                         invert=True,
                         regex='(?m)(?s).*(id="%s").*' % (self.country,))
     return txt
Example #3
0
    def flatten(self, data=None, internal=False):
        '''
            Convert image to a cylindrical projection and return
            the converted data.
        '''

        if not data:
            data = self.filedata

        if not self.idata:
            data = re.sub(self.r_coords, self.expand_values, data)
            fixer = tagFix()
            data = fixer.tagfix('p',
                                data,
                                matchfunc=self.fix_pin,
                                regex=self.r_pin)
        else:
            print "  Skipping flatten step as unnecessary."

        if not internal:
            data = self.viewport_set(data)
            if self.pins:
                data = re.sub('</svg>', self.get_pins() + '</svg>', data)
            self.write_imagemap(data, flat_output=True)
        return data
Example #4
0
 def flatness(self, data):
     self.isflat = True
     fixer = tagFix()
     fixer.tagfix('path', data,
                  regex='(?m)(?s).*id="ocean".*',
                  matchfunc=self.flatness_check1)
     return self.isflat
 def shrink_image(self, data ):
     data = re.sub( self.r_coords, self.shrink_values, data )
     fixer = tagFix()
     ret = fixer.tagfix('path',data,
                         matchfunc=self.fix_pin,
                         regex=self.r_pin)
     return ret
Example #6
0
 def imagemap_contiguous_country(self, txt):
     fixer = tagFix()
     fixer.tagfix('path',
                  txt,
                  matchfunc=self.imagemap_process_anchor,
                  regex='(?m)(?s).*id="%s".*' %
                  (self.imagemap_countrydata['code'], ))
     return ''
 def offset_ocean(self, offset):
     self.offset = offset
     self.centerpos += -offset
     fixer = tagFix()
     self.data = fixer.tagfix( 'path', 
                              self.data, 
                              matchfunc=self.fix_ocean, 
                              regex='.*id="ocean".*' )
Example #8
0
 def isolate_contiguous_country(self, txt):
     fixer = tagFix()
     txt = fixer.tagfix('path',
                        txt,
                        matchfunc=self.delete_tag,
                        invert=True,
                        regex='(?m)(?s).*(id="%s").*' % (self.country, ))
     return txt
Example #9
0
 def imagemap_pinpoint(self, data, pinpoint):
     '''
         Store the HTML anchor(s) for the specified pinpoint on a string variable.
     '''
     self.imagemap_pinpointdata = pinpoint
     fixer = tagFix()
     fixer.tagfix('path', data, 
                  matchfunc=self.imagemap_process_pinpoint,
                  regex='(?m)(?s).*id="%s[_"].*' % (pinpoint['name'],))
Example #10
0
 def imagemap_pinpoint(self, data, pinpoint):
     '''
         Store the HTML anchor(s) for the specified pinpoint on a string variable.
     '''
     self.imagemap_pinpointdata = pinpoint
     fixer = tagFix()
     fixer.tagfix('path',
                  data,
                  matchfunc=self.imagemap_process_pinpoint,
                  regex='(?m)(?s).*id="%s[_"].*' % (pinpoint['name'], ))
Example #11
0
 def imagemap_country(self, data, country):
     '''
         Store the HTML anchor(s) for the specified country on a string variable.
     '''
     self.imagemap_countrydata = country
     fixer = tagFix()
     fixer.tagfix('g', data, 
                  nonmatchfunc=self.imagemap_contiguous_country,
                  matchfunc=self.imagemap_noncontiguous_country,
                  level=1,
                  regex='(?m)(?s).*id="%s".*' % (country['code'],))
Example #12
0
 def imagemap_country(self, data, country):
     '''
         Store the HTML anchor(s) for the specified country on a string variable.
     '''
     self.imagemap_countrydata = country
     fixer = tagFix()
     fixer.tagfix('g',
                  data,
                  nonmatchfunc=self.imagemap_contiguous_country,
                  matchfunc=self.imagemap_noncontiguous_country,
                  level=1,
                  regex='(?m)(?s).*id="%s".*' % (country['code'], ))
Example #13
0
 def viewport_set(self, data):
     if not self.render_width and not self.render_height:
         return data
     r = re.match('(?m)(?s).*<path[^>]*id="ocean".*', data)
     if r:
         self.viewport_invert = False
         self.viewport_regex = '(?m)(?s).*id="ocean".*'
     else:
         self.viewport_invert = True
         self.viewport_regex = '(?m)(?s).*class="pinpoint.*'
     fixer = tagFix()
     return self.viewport_from_paths( data )
Example #14
0
 def isolate_country(self, country):
     self.country = country
     data = self.flatten( internal=True )
     fixer = tagFix()
     data = fixer.tagfix('g', data, 
                   matchfunc=self.delete_noncontiguous,
                   nonmatchfunc=self.isolate_contiguous_country,
                   level=1,
                   invert=True,
                   regex='(?m)(?s).*id="%s".*' % (country,))
     if country == 'us':
         data = self.repair_us_country_view( data )
     if self.is_noncontiguous:
         fixer = tagFix()
         data = fixer.tagfix('path', data,
                       matchfunc=self.delete_tag,
                       regex='(?m)(?s).*class="[^"]*(hidden|circle).*')
     data = self.viewport_set( data )
     if self.pins:
         data = re.sub( '</svg>', self.get_pins( country=country ) + '</svg>', data )
     self.write_imagemap( data, flat_output=True )
     return data
Example #15
0
 def apply_translations(self, data ):
     '''
         Internal function.
     
         For all groups containing a translation transform attribute,
         invoke tagfix to apply the translation values to all 
         coordinates within the scope of the group.
     '''
     fixer = tagFix()
     data = fixer.tagfix( 'path',
                         data,
                         matchfunc=self.perform_translation, 
                         regex=self.r_ptrans )
     return fixer.tagfix( 'g',
                         data, 
                         matchfunc=self.perform_translation, 
                         regex=self.r_group_head )
Example #16
0
 def isolate_country(self, country):
     self.country = country
     data = self.flatten(internal=True)
     fixer = tagFix()
     data = fixer.tagfix('g',
                         data,
                         matchfunc=self.delete_tag,
                         nonmatchfunc=self.isolate_contiguous_country,
                         level=1,
                         invert=True,
                         regex='(?m)(?s).*id="%s".*' % (country, ))
     if country == 'us':
         data = self.repair_us_country_view(data)
     data = self.viewport_set(data)
     if self.pins:
         data = re.sub('</svg>',
                       self.get_pins(country=country) + '</svg>', data)
     self.write_imagemap(data, flat_output=True)
     return data
Example #17
0
 def clone(self, data=None ):
     
     if not data:
         data = self.filedata
     
     offset = '%0.4f' %(self.maxhalfwidth * 2)
     self.clone_offset = offset
     self.initialize_constants()
     self.template = self.template.replace('@@offset@@', offset)
     if not self.idata:
         data = self.flatten( data=data, internal=True )
     data = self.viewport_set( data )
     if self.pins:
         data = re.sub( '</svg>', self.get_pins() + '</svg>', data )
     fixer = tagFix()
     data = fixer.tagfix( 'g', 
                         data, 
                         matchfunc=self.fix_grouped_country, 
                         nonmatchfunc=self.fix_top_path, 
                         level=1 )
     #open('broken_file_before.svg', 'w+').write(data)
     data = self.apply_translations( data )
     #open('broken_file_after.svg', 'w+').write(data)
     return data
Example #18
0
    def clone(self, data=None):

        if not data:
            data = self.filedata

        offset = '%0.4f' % (self.maxhalfwidth * 2)
        self.clone_offset = offset
        self.initialize_constants()
        self.template = self.template.replace('@@offset@@', offset)
        if not self.idata:
            data = self.flatten(data=data, internal=True)
        data = self.viewport_set(data)
        if self.pins:
            data = re.sub('</svg>', self.get_pins() + '</svg>', data)
        fixer = tagFix()
        data = fixer.tagfix('g',
                            data,
                            matchfunc=self.fix_grouped_country,
                            nonmatchfunc=self.fix_top_path,
                            level=1)
        #open('broken_file_before.svg', 'w+').write(data)
        data = self.apply_translations(data)
        #open('broken_file_after.svg', 'w+').write(data)
        return data
Example #19
0
 def viewport_from_paths(self, data):
     self.viewport = [10000,10000,-10000,-10000]
     fixer = tagFix()
     fixer.tagfix('path', data, matchfunc=self.get_viewport, invert=self.viewport_invert, regex=self.viewport_regex)
     self.viewport[0] += -1
     self.viewport[1] += -1
     maxpinradius = self.get_max_pin_radius()
     self.viewport[0] += - maxpinradius
     self.viewport[1] += - maxpinradius
     self.viewport[2] += maxpinradius
     self.viewport[3] += maxpinradius
     self.viewport_width = self.viewport[2] - self.viewport[0]
     self.viewport_height = self.viewport[3] - self.viewport[1]
     
     # Adjust output dimensions, for reference when rendering bitmaps
     if not self.render_height:
         self.render_height = self.get_render_height()
     elif not self.render_width:
         self.render_width = self.get_render_width()
     if self.render_height > self.get_render_height:
         self.render_height = self.get_render_height()
     elif self.render_width > self.get_render_width():
         self.render_width = self.get_render_width()
     return self.adjust_viewport( data )
Example #20
0
 def delete_script(self):
     t = tagFix()
     self.html = t.tagfix('script',self.html,
                          matchfunc=deleteme)
Example #21
0
 def fix_top_path(self, data):
     fixer = tagFix(debug=True)
     return fixer.tagfix('path', data, matchfunc=self.fix_path)
Example #22
0
 def imagemap_noncontiguous_country(self, txt):
     fixer = tagFix()
     fixer.tagfix('path', txt,
                  matchfunc=self.imagemap_process_anchor)
     return ''
Example #23
0
 def imagemap_contiguous_country(self, txt):
     fixer = tagFix()
     fixer.tagfix('path', txt,
                  matchfunc=self.imagemap_process_anchor,
                  regex='(?m)(?s).*id="%s".*' % (self.imagemap_countrydata['code'],))
     return ''
Example #24
0
 def quote_onclick(self):
     t = tagFix()
     self.html = t.tagfix('a',self.html,
                          regex='.*onClick="([^"?]*)\?([^"]*)".*',
                          matchfunc=quote_onclick)
Example #25
0
 def fix_top_path(self, data):
     fixer = tagFix(debug=True)
     return fixer.tagfix('path', data, matchfunc=self.fix_path)
Example #26
0
 def imagemap_noncontiguous_country(self, txt):
     fixer = tagFix()
     fixer.tagfix('path', txt, matchfunc=self.imagemap_process_anchor)
     return ''
Example #27
0
 def quote_href(self):
     t = tagFix()
     self.html = t.tagfix('a',self.html,
                          regex='.*href="([^"?]*)\?([^"]*)".*',
                          matchfunc=quote_href)