Exemple #1
0
  def on_begin( self):
    self.paper.unselect_all()
    scale = 720.0/self.paper.winfo_fpixels( '254m')
    if self.paper.get_paper_property( 'crop_svg'):
      margin = self.paper.get_paper_property('crop_margin')
      items = list( self.paper.find_all())
      items.remove( self.paper.background)

      if not items:
        Store.log( _('There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'), message_type="error")
        return 0

      x1, y1, x2, y2 = self.paper.list_bbox( items)
      self.transformer = transform.transform()
      self.transformer.set_move( -x1+margin, -y1+margin)
      self.transformer.set_scaling( scale)
      dx = x2-x1 +2*margin
      dy = y2-y1 +2*margin
    else:
      self.transformer = transform.transform()
      self.transformer.set_scaling( scale)
      dx = Screen.mm_to_px( self.paper._paper_properties['size_x'])
      dy = Screen.mm_to_px( self.paper._paper_properties['size_y'])

    self.canvas = self.init_canvas( pagesize=(scale*dx, scale*dy))
    self.converter = self.converter_class()
    return 1
Exemple #2
0
  def on_begin( self, scaling=None):
    self.paper.unselect_all()
    if self.paper.get_paper_property( 'crop_svg'):

      if len( self.paper.find_all()) <= 1: # background only
        Store.log( _('There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'), message_type="error")
        return 0

      x1, y1, x2, y2 = self.paper.get_cropping_bbox()
      dx = x2-x1
      dy = y2-y1
      scalex, scaley = scaling or self.get_scaling( dx, dy)
      if not scalex:
        # the setting of scaling was canceled
        return 0

      self.transformer = transform.transform()
      self.transformer.set_move( -x1, -y1)
      self.transformer.set_scaling_xy( scalex, scaley)
    else:
      dx = Screen.mm_to_px( self.paper._paper_properties['size_x'])
      dy = Screen.mm_to_px( self.paper._paper_properties['size_y'])
      scalex, scaley = scaling or self.get_scaling( dx, dy)
      if not scalex:
        # the setting of scaling was canceled
        return 0

      self.transformer = transform.transform()
      self.transformer.set_scaling_xy( scalex, scaley)

    x1, y1, x2, y2 = self.transformer.transform_4( (0, 0, dx, dy))
    self.pagesize = tuple( map( round, (x2-x1, y2-y1)))
    self.attrs['text_to_curves'] = False
    self.converter = self.converter_class( **self.attrs)
    return 1
  def on_begin( self, scaling=None):
    self.paper.unselect_all()
    if self.paper.get_paper_property( 'crop_svg'):

      if len( self.paper.find_all()) <= 1: # background only
        Store.log( _('There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'), message_type="error")
        return 0

      x1, y1, x2, y2 = self.paper.get_cropping_bbox()
      dx = x2-x1
      dy = y2-y1
      scalex, scaley = scaling or self.get_scaling( dx, dy)
      if not scalex:
        # the setting of scaling was canceled
        return 0

      self.transformer = transform.transform()
      self.transformer.set_move( -x1, -y1)
      self.transformer.set_scaling_xy( scalex, scaley)
    else:
      dx = Screen.mm_to_px( self.paper._paper_properties['size_x'])
      dy = Screen.mm_to_px( self.paper._paper_properties['size_y'])
      scalex, scaley = scaling or self.get_scaling( dx, dy)
      if not scalex:
        # the setting of scaling was canceled
        return 0

      self.transformer = transform.transform()
      self.transformer.set_scaling_xy( scalex, scaley)

    x1, y1, x2, y2 = self.transformer.transform_4( (0, 0, dx, dy))
    self.pagesize = tuple( map( round, (x2-x1, y2-y1)))
    self.attrs['text_to_curves'] = False
    self.converter = self.converter_class( **self.attrs)
    return 1
Exemple #4
0
    def on_begin(self):
        self.paper.unselect_all()
        scale = 720.0 / self.paper.winfo_fpixels('254m')
        if self.paper.get_paper_property('crop_svg'):
            margin = self.paper.get_paper_property('crop_margin')
            items = list(self.paper.find_all())
            items.remove(self.paper.background)

            if not items:
                Store.log(_(
                    'There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'
                ),
                          message_type="error")
                return 0

            x1, y1, x2, y2 = self.paper.list_bbox(items)
            self.transformer = transform.transform()
            self.transformer.set_move(-x1 + margin, -y1 + margin)
            self.transformer.set_scaling(scale)
            dx = x2 - x1 + 2 * margin
            dy = y2 - y1 + 2 * margin
        else:
            self.transformer = transform.transform()
            self.transformer.set_scaling(scale)
            dx = Screen.mm_to_px(self.paper._paper_properties['size_x'])
            dy = Screen.mm_to_px(self.paper._paper_properties['size_y'])

        self.canvas = self.init_canvas(pagesize=(scale * dx, scale * dy))
        self.converter = self.converter_class()
        return 1
Exemple #5
0
    def construct_dom_tree(self, top_levels):
        """Construct the SVG dom from all top_levels.

    """
        # the constants
        border_size = self.paper.get_paper_property('crop_margin')

        # converter
        px_to_cm_txt = lambda x: Screen.px_to_text_with_unit(
            x, unit="cm", round_to=5)
        px_to_mm_txt = lambda x: Screen.px_to_text_with_unit(
            x, unit="mm", round_to=5)

        # the code
        self._id = 0
        doc = self.document
        self.top = dom_extensions.elementUnder(
            doc,
            "svg",
            attributes=(("xmlns", "http://www.w3.org/2000/svg"), ("version",
                                                                  "1.0")))
        if self.full_size:
            sx = self.paper.get_paper_property('size_x')
            sy = self.paper.get_paper_property('size_y')
            dom_extensions.setAttributes(
                self.top, (("width", '%fmm' % sx), ("height", '%fmm' % sy),
                           ('viewBox', '0 0 %d %d' %
                            (Screen.mm_to_px(sx), Screen.mm_to_px(sy)))))
        else:
            items = list(self.paper.find_all())
            items.remove(self.paper.background)
            x1, y1, x2, y2 = self.paper.list_bbox(items)
            w = px_to_mm_txt(x2 - x1 + 2 * border_size)
            h = px_to_mm_txt(y2 - y1 + 2 * border_size)
            bx2, by2 = x2 - x1 + 2 * border_size, y2 - y1 + 2 * border_size
            dom_extensions.setAttributes(
                self.top, (("width", w), ("height", h),
                           ("viewBox", '0 0 %d %d' % (bx2, by2))))
        self.group = dom_extensions.elementUnder(self.top, 'g',
                                                 (('font-size', '12pt'),
                                                  ('font-family', 'Helvetica'),
                                                  ('stroke-linecap', 'round')))
        if not self.full_size:
            self.group.setAttribute(
                'transform',
                'translate(%d,%d)' % (-x1 + border_size, -y1 + border_size))

        # sort the top_levels according to paper.stack
        cs = []
        for c in self.paper.stack:
            if c in top_levels:
                cs.append(c)
        for o in cs:
            if o.object_type == 'molecule':
                for b in o.bonds:
                    self.add_bond(b)
                for a in o.atoms:
                    self.add_atom(a)
            elif o.object_type == 'arrow':
                self.add_arrow(o)
            elif o.object_type == 'text':
                self.add_text(o)
            elif o.object_type == 'plus':
                self.add_plus(o)
            elif o.object_type in data.vector_graphics_types:
                if o.object_type == 'rect':
                    self.add_rect(o)
                elif o.object_type == 'oval':
                    self.add_oval(o)
                elif o.object_type == 'polygon':
                    self.add_polygon(o)
                elif o.object_type == 'polyline':
                    self.add_polyline(o)
Exemple #6
0
  def write_to_file( self, name):
     #{"v BKChemu bond.type":"v ChemDraw hodnota atributu Display elementu b"}
    bondType={"w":"WedgeBegin",
          "h":"WedgedHashBegin",
          "a":"Wavy",
          "b":"Bold",
          "d":"Dash",
          "o":"Dash"
          }

    #{"arrow.type v BKChemu":["graphic/ArrowType","arrow/ArrowheadHead","arrow/   ArrowheadTail","arrow/ArrowheadType"]}
    #"retro":["RetroSynthetic","Full","","Angle"] - nefunguje, potrebuje dalsi povinne atributy
    arrowType={"equilibrium":["Equilibrium","HalfLeft","HalfLeft","Solid"],
           "equilibrium2":["Equilibrium","HalfLeft","HalfLeft","Solid"],
           "normal":["FullHead","Full","","Solid"],
           "electron":["HalfHead","HalfLeft","","Solid"]
           }

    colors=["#ffffff","#000000","#ff0000","#ffff00","#00ff00","#00ffff","#0000ff","#ff00ff"]

    fonts=["Arial","Times New Roman"]

    out=dom.Document()
    root=out.createElement("CDXML")
    out.appendChild(root)
    elem01=out.createElement("colortable")
    root.appendChild(elem01)

    elem03=out.createElement("fonttable")
    root.appendChild(elem03)

    elem1=out.createElement("page")
    root.appendChild(elem1)
    PaperX=int(Screen.mm_to_px( self.paper.get_paper_property("size_x") ) )
    PaperY=int(Screen.mm_to_px( self.paper.get_paper_property("size_y") ) )
    elem1.setAttribute("BoundingBox","%d %d %d %d" % (0,0,PaperX,PaperY) )
    elem1.setAttribute("Width",str(PaperX) )
    elem1.setAttribute("Height",str(PaperY) )
    elem1.setAttribute("DrawingSpace","poster")

    for mol in self.paper.molecules:
      elem2=out.createElement("fragment")
      elem1.appendChild(elem2)

      for atom in mol.atoms:
        elem3=out.createElement("n")
        elem2.appendChild(elem3)
        elem3.setAttribute("id",re.sub("atom","",atom.id) )
        elem3.setAttribute("p","%f %f" %(atom.x,atom.y) )
        elem3.setAttribute("NumHydrogens","%d" % atom.free_valency)

        if atom.symbol != "C" or atom.show:
          elem4=out.createElement("t")
          elem3.appendChild(elem4)
          elem6=out.createElement("s")
          elem6.setAttribute("size",str(atom.font_size) )
          elem6.setAttribute("face","96")
          elem4.appendChild(elem6)
          text4 = re.sub( "<.*?>", "", atom.xml_ftext)
          if text4:
            symbol=out.createTextNode(text4)
            elem6.appendChild(symbol)
          else:
            symbol=out.createTextNode(atom.xml_ftext)
            elem6.appendChild(symbol)
          NewColor=self.paper.any_color_to_rgb_string( atom.line_color)
          if NewColor not in colors:
            colors.append (NewColor)
          for color in colors:
            if color==NewColor:
              ShowColor=str(colors.index(color)+2)
          elem4.setAttribute("color",ShowColor)
          elem6.setAttribute("color",ShowColor)

          NewFont=atom.font_family
          if NewFont not in fonts:
            fonts.append(NewFont)
          for font in fonts:
            if font==NewFont:
              FontId=str(fonts.index(font)+3)
          elem6.setAttribute("font",FontId)

      for bond in mol.bonds:
        elem5=out.createElement("b")
        elem2.appendChild(elem5)
        elem5.setAttribute("B",re.sub("atom","",bond.atom1.id) )
        elem5.setAttribute("E",re.sub("atom","",bond.atom2.id) )
        for bondB, bondC in bondType.items():
          if bond.type==bondB:
            elem5.setAttribute("Display",bondC)
          elif bond.type=="h" and bond.equithick==1:
            elem5.setAttribute("Display","Hash")

        NewColor=self.paper.any_color_to_rgb_string( bond.line_color)
        if NewColor not in colors:
          colors.append (NewColor)
        for color in colors:
          if color==NewColor:
            ShowColor=str(colors.index(color)+2)
        elem5.setAttribute("color",ShowColor)

        #print int( self.paper.any_color_to_rgb_string( bond.line_color)[1:3], 16)
        if bond.order > 1:
          elem5.setAttribute("Order","%d" % bond.order )
        #print bond.type,bond.equithick,bond.simple_double

    for text in self.paper.texts:
      elem7=out.createElement("t")
      elem1.appendChild(elem7)
      elem7.setAttribute("id",re.sub("text","",text.id))
      elem7.setAttribute("p","%f %f" % (text.x,text.y))
      elem7.setAttribute("BoundingBox","%d %d %d %d" % (text.bbox()[0],text.bbox()[1],text.bbox()[2],text.bbox()[3]) )

      minidoc = dom.parseString( "<a>%s</a>" % text.xml_ftext.encode('utf-8'))
      textik={"i":2,
              "b":1,
              "sub":32,
              "sup":64
              }

      def get_text( el):
        texts = []
        for ch in el.childNodes:
          if isinstance( ch, dom.Text):
            parents = []
            par = ch.parentNode
            while not isinstance( par, dom.Document):
              parents.append( str(par.nodeName))
              par = par.parentNode
            texts.append((ch.nodeValue, parents))
          else:
            texts += get_text( ch)
        return texts

      texts2= get_text(minidoc.childNodes[0])

      for text2 in texts2:
        elem001=out.createElement("s")
        elem7.appendChild(elem001)
        elem001.setAttribute("size", str(text.font_size))
        text001=out.createTextNode(text2[0])
        elem001.appendChild(text001)

        def LogOR(xs):
          if len(xs) == 0:
            return 0
          else:
            return xs[0] | LogOR (xs[1:])

        Faces=[]

        for xxx in text2[1]:
          for P, F in textik.items():
            if P==xxx:
              Faces.append(F)

        Face=LogOR(Faces)
        if Face!=0:
          elem001.setAttribute("face",str(Face) )

        NewFont=text.font_family
        if NewFont not in fonts:
          fonts.append(NewFont)
        for font in fonts:
          if font==NewFont:
            FontId=str(fonts.index(font)+3)
        elem001.setAttribute("font",FontId)

        NewColor=self.paper.any_color_to_rgb_string(text.line_color)
        if NewColor not in colors:
          colors.append (NewColor)
        for color in colors:
          if color==NewColor:
            ShowColor=str(colors.index(color)+2)
        elem001.setAttribute("color",ShowColor)
        elem7.setAttribute("color",ShowColor)

    for plus in self.paper.pluses:
      elem9=out.createElement("graphic")
      elem1.appendChild(elem9)
      elem9.setAttribute("SymbolType","Plus")
      elem9.setAttribute("BoundingBox","%f %f %f %f" % plus.bbox())
      elem9.setAttribute("GraphicType","Symbol")
      elem9.setAttribute("id",re.sub("plus","",plus.id))
      #print plus.bbox()
      NewColor=self.paper.any_color_to_rgb_string(plus.line_color)
      if NewColor not in colors:
        colors.append (NewColor)
      for color in colors:
        if color==NewColor:
          ShowColor=str(colors.index(color)+2)
      elem9.setAttribute("color",ShowColor)

    for arrow in self.paper.arrows:
      arrowPoints=[p.get_xy() for p in arrow.points]

      elem10=out.createElement("graphic")
      elem1.appendChild(elem10)
      elem10.setAttribute("GraphicType","Line")
      for arrowB, arrowC in arrowType.items():
          if arrow.type==arrowB:
            elem10.setAttribute("ArrowType",arrowC[0])
      NewColor=self.paper.any_color_to_rgb_string(arrow.line_color)
      if NewColor not in colors:
        colors.append (NewColor)
      for color in colors:
        if color==NewColor:
          ShowColor=str(colors.index(color)+2)
      elem10.setAttribute("color",ShowColor)

      elem11=out.createElement("arrow")
      elem1.appendChild(elem11)
      for arrowB, arrowC in arrowType.items():
          if arrow.type==arrowB:
            elem11.setAttribute("ArrowheadHead",arrowC[1])
            elem11.setAttribute("ArrowheadTail",arrowC[2])
            elem11.setAttribute("ArrowheadType",arrowC[3])
      elem11.setAttribute("Head3D",str(arrowPoints[-1][0])+" "+str(arrowPoints[-1][1]))
      elem11.setAttribute("Tail3D",str(arrowPoints[0][0])+" "+str(arrowPoints[0][1]))
      elem11.setAttribute("BoundingBox","%f %f %f %f" % (arrowPoints[-1][0],arrowPoints[-1][1],arrowPoints[0][0],arrowPoints[0][1]) )
      elem11.setAttribute("color",ShowColor)
      #print arrow
      #print arrow.type

    for color in colors:
      elem02=out.createElement("color")
      elem01.appendChild(elem02)
      red=str(int(color[1:3],16)/255.0)
      green=str(int(color[3:5],16)/255.0)
      blue=str(int(color[5:7],16)/255.0)

      elem02.setAttribute("r",red)
      elem02.setAttribute("g",green)
      elem02.setAttribute("b",blue)

    FontId=3
    for font in fonts:
      elem04=out.createElement("font")
      elem03.appendChild(elem04)
      elem04.setAttribute("id",str(FontId) )
      FontId+=1
      elem04.setAttribute("name",font)

    with open(name, 'wb') as f:
      f.write(out.toxml('utf-8'))
Exemple #7
0
  def construct_dom_tree( self, top_levels):
    """constructs the SVG dom from all top_levels"""
    # the constants
    border_size = self.paper.get_paper_property( 'crop_margin')

    # converter
    px_to_cm_txt = lambda x: Screen.px_to_text_with_unit( x, unit="cm", round_to=5)
    px_to_mm_txt = lambda x: Screen.px_to_text_with_unit( x, unit="mm", round_to=5)

    # the code
    self._id = 0
    doc = self.document
    self.top = dom_extensions.elementUnder( doc, "svg", attributes=(("xmlns", "http://www.w3.org/2000/svg"),
                                                                    ("version", "1.0")))
    if self.full_size:
      sx = self.paper.get_paper_property( 'size_x')
      sy = self.paper.get_paper_property( 'size_y')
      dom_extensions.setAttributes( self.top, (("width", '%fmm' % sx),
                                               ("height", '%fmm' % sy),
                                               ('viewBox', '0 0 %d %d' % (Screen.mm_to_px(sx), Screen.mm_to_px(sy)))))
    else:
      items = list( self.paper.find_all())
      items.remove( self.paper.background)
      x1, y1, x2, y2 = self.paper.list_bbox( items)
      w = px_to_mm_txt( x2 -x1 +2*border_size)
      h = px_to_mm_txt( y2 -y1 +2*border_size)
      bx2, by2 = x2-x1+2*border_size, y2-y1+2*border_size
      dom_extensions.setAttributes( self.top, (("width", w),
                                               ("height", h),
                                               ("viewBox",'0 0 %d %d' % ( bx2, by2))))
    self.group = dom_extensions.elementUnder( self.top, 'g',
                                              (('font-size', '12pt'),
                                               ('font-family', 'Helvetica'),
                                               ('stroke-linecap', 'round')))
    if not self.full_size:
      self.group.setAttribute( 'transform', 'translate(%d,%d)' % (-x1+border_size, -y1+border_size))
      
    # sort the top_levels according to paper.stack
    cs = []
    for c in self.paper.stack:
      if c in top_levels:
        cs.append( c)
    for o in cs:
      if o.object_type == 'molecule':
        for b in o.bonds:
          self.add_bond( b)
        for a in o.atoms:
          self.add_atom( a)
      elif o.object_type == 'arrow':
        self.add_arrow( o)
      elif o.object_type == 'text':
        self.add_text( o)
      elif o.object_type == 'plus':
        self.add_plus( o)
      elif o.object_type in data.vector_graphics_types:
        if o.object_type == 'rect':
          self.add_rect( o)
        elif o.object_type == 'oval':
          self.add_oval( o)
        elif o.object_type == 'polygon':
          self.add_polygon( o)
        elif o.object_type == 'polyline':
          self.add_polyline( o)
Exemple #8
0
    def write_to_file(self, name):
        #{"v BKChemu bond.type":"v ChemDraw hodnota atributu Display elementu b"}
        bondType = {
            "w": "WedgeBegin",
            "h": "WedgedHashBegin",
            "a": "Wavy",
            "b": "Bold",
            "d": "Dash",
            "o": "Dash"
        }

        #{"arrow.type v BKChemu":["graphic/ArrowType","arrow/ArrowheadHead","arrow/   ArrowheadTail","arrow/ArrowheadType"]}
        #"retro":["RetroSynthetic","Full","","Angle"] - nefunguje, potrebuje dalsi povinne atributy
        arrowType = {
            "equilibrium": ["Equilibrium", "HalfLeft", "HalfLeft", "Solid"],
            "equilibrium2": ["Equilibrium", "HalfLeft", "HalfLeft", "Solid"],
            "normal": ["FullHead", "Full", "", "Solid"],
            "electron": ["HalfHead", "HalfLeft", "", "Solid"]
        }

        colors = [
            "#ffffff", "#000000", "#ff0000", "#ffff00", "#00ff00", "#00ffff",
            "#0000ff", "#ff00ff"
        ]

        fonts = ["Arial", "Times New Roman"]

        out = dom.Document()
        root = out.createElement("CDXML")
        out.appendChild(root)
        elem01 = out.createElement("colortable")
        root.appendChild(elem01)

        elem03 = out.createElement("fonttable")
        root.appendChild(elem03)

        elem1 = out.createElement("page")
        root.appendChild(elem1)
        PaperX = int(Screen.mm_to_px(self.paper.get_paper_property("size_x")))
        PaperY = int(Screen.mm_to_px(self.paper.get_paper_property("size_y")))
        elem1.setAttribute("BoundingBox",
                           "%d %d %d %d" % (0, 0, PaperX, PaperY))
        elem1.setAttribute("Width", str(PaperX))
        elem1.setAttribute("Height", str(PaperY))
        elem1.setAttribute("DrawingSpace", "poster")

        for mol in self.paper.molecules:
            elem2 = out.createElement("fragment")
            elem1.appendChild(elem2)

            for atom in mol.atoms:
                elem3 = out.createElement("n")
                elem2.appendChild(elem3)
                elem3.setAttribute("id", re.sub("atom", "", atom.id))
                elem3.setAttribute("p", "%f %f" % (atom.x, atom.y))
                elem3.setAttribute("NumHydrogens", "%d" % atom.free_valency)

                if atom.symbol != "C" or atom.show:
                    elem4 = out.createElement("t")
                    elem3.appendChild(elem4)
                    elem6 = out.createElement("s")
                    elem6.setAttribute("size", str(atom.font_size))
                    elem6.setAttribute("face", "96")
                    elem4.appendChild(elem6)
                    text4 = re.sub("<.*?>", "", atom.xml_ftext)
                    if text4:
                        symbol = out.createTextNode(text4)
                        elem6.appendChild(symbol)
                    else:
                        symbol = out.createTextNode(atom.xml_ftext)
                        elem6.appendChild(symbol)
                    NewColor = self.paper.any_color_to_rgb_string(
                        atom.line_color)
                    if NewColor not in colors:
                        colors.append(NewColor)
                    for color in colors:
                        if color == NewColor:
                            ShowColor = str(colors.index(color) + 2)
                    elem4.setAttribute("color", ShowColor)
                    elem6.setAttribute("color", ShowColor)

                    NewFont = atom.font_family
                    if NewFont not in fonts:
                        fonts.append(NewFont)
                    for font in fonts:
                        if font == NewFont:
                            FontId = str(fonts.index(font) + 3)
                    elem6.setAttribute("font", FontId)

            for bond in mol.bonds:
                elem5 = out.createElement("b")
                elem2.appendChild(elem5)
                elem5.setAttribute("B", re.sub("atom", "", bond.atom1.id))
                elem5.setAttribute("E", re.sub("atom", "", bond.atom2.id))
                for bondB, bondC in bondType.items():
                    if bond.type == bondB:
                        elem5.setAttribute("Display", bondC)
                    elif bond.type == "h" and bond.equithick == 1:
                        elem5.setAttribute("Display", "Hash")

                NewColor = self.paper.any_color_to_rgb_string(bond.line_color)
                if NewColor not in colors:
                    colors.append(NewColor)
                for color in colors:
                    if color == NewColor:
                        ShowColor = str(colors.index(color) + 2)
                elem5.setAttribute("color", ShowColor)

                #print int( self.paper.any_color_to_rgb_string( bond.line_color)[1:3], 16)
                if bond.order > 1:
                    elem5.setAttribute("Order", "%d" % bond.order)
                #print bond.type,bond.equithick,bond.simple_double

        for text in self.paper.texts:
            elem7 = out.createElement("t")
            elem1.appendChild(elem7)
            elem7.setAttribute("id", re.sub("text", "", text.id))
            elem7.setAttribute("p", "%f %f" % (text.x, text.y))
            elem7.setAttribute(
                "BoundingBox",
                "%d %d %d %d" % (text.bbox()[0], text.bbox()[1],
                                 text.bbox()[2], text.bbox()[3]))

            minidoc = dom.parseString("<a>%s</a>" %
                                      text.xml_ftext.encode('utf-8'))
            textik = {"i": 2, "b": 1, "sub": 32, "sup": 64}

            def get_text(el):
                texts = []
                for ch in el.childNodes:
                    if isinstance(ch, dom.Text):
                        parents = []
                        par = ch.parentNode
                        while not isinstance(par, dom.Document):
                            parents.append(str(par.nodeName))
                            par = par.parentNode
                        texts.append((ch.nodeValue, parents))
                    else:
                        texts += get_text(ch)
                return texts

            texts2 = get_text(minidoc.childNodes[0])

            for text2 in texts2:
                elem001 = out.createElement("s")
                elem7.appendChild(elem001)
                elem001.setAttribute("size", str(text.font_size))
                text001 = out.createTextNode(text2[0])
                elem001.appendChild(text001)

                def LogOR(xs):
                    if len(xs) == 0:
                        return 0
                    else:
                        return xs[0] | LogOR(xs[1:])

                Faces = []

                for xxx in text2[1]:
                    for P, F in textik.items():
                        if P == xxx:
                            Faces.append(F)

                Face = LogOR(Faces)
                if Face != 0:
                    elem001.setAttribute("face", str(Face))

                NewFont = text.font_family
                if NewFont not in fonts:
                    fonts.append(NewFont)
                for font in fonts:
                    if font == NewFont:
                        FontId = str(fonts.index(font) + 3)
                elem001.setAttribute("font", FontId)

                NewColor = self.paper.any_color_to_rgb_string(text.line_color)
                if NewColor not in colors:
                    colors.append(NewColor)
                for color in colors:
                    if color == NewColor:
                        ShowColor = str(colors.index(color) + 2)
                elem001.setAttribute("color", ShowColor)
                elem7.setAttribute("color", ShowColor)

        for plus in self.paper.pluses:
            elem9 = out.createElement("graphic")
            elem1.appendChild(elem9)
            elem9.setAttribute("SymbolType", "Plus")
            elem9.setAttribute("BoundingBox", "%f %f %f %f" % plus.bbox())
            elem9.setAttribute("GraphicType", "Symbol")
            elem9.setAttribute("id", re.sub("plus", "", plus.id))
            #print plus.bbox()
            NewColor = self.paper.any_color_to_rgb_string(plus.line_color)
            if NewColor not in colors:
                colors.append(NewColor)
            for color in colors:
                if color == NewColor:
                    ShowColor = str(colors.index(color) + 2)
            elem9.setAttribute("color", ShowColor)

        for arrow in self.paper.arrows:
            arrowPoints = [p.get_xy() for p in arrow.points]

            elem10 = out.createElement("graphic")
            elem1.appendChild(elem10)
            elem10.setAttribute("GraphicType", "Line")
            for arrowB, arrowC in arrowType.items():
                if arrow.type == arrowB:
                    elem10.setAttribute("ArrowType", arrowC[0])
            NewColor = self.paper.any_color_to_rgb_string(arrow.line_color)
            if NewColor not in colors:
                colors.append(NewColor)
            for color in colors:
                if color == NewColor:
                    ShowColor = str(colors.index(color) + 2)
            elem10.setAttribute("color", ShowColor)

            elem11 = out.createElement("arrow")
            elem1.appendChild(elem11)
            for arrowB, arrowC in arrowType.items():
                if arrow.type == arrowB:
                    elem11.setAttribute("ArrowheadHead", arrowC[1])
                    elem11.setAttribute("ArrowheadTail", arrowC[2])
                    elem11.setAttribute("ArrowheadType", arrowC[3])
            elem11.setAttribute(
                "Head3D",
                str(arrowPoints[-1][0]) + " " + str(arrowPoints[-1][1]))
            elem11.setAttribute(
                "Tail3D",
                str(arrowPoints[0][0]) + " " + str(arrowPoints[0][1]))
            elem11.setAttribute(
                "BoundingBox",
                "%f %f %f %f" % (arrowPoints[-1][0], arrowPoints[-1][1],
                                 arrowPoints[0][0], arrowPoints[0][1]))
            elem11.setAttribute("color", ShowColor)
            #print arrow
            #print arrow.type

        for color in colors:
            elem02 = out.createElement("color")
            elem01.appendChild(elem02)
            red = str(int(color[1:3], 16) / 255.0)
            green = str(int(color[3:5], 16) / 255.0)
            blue = str(int(color[5:7], 16) / 255.0)

            elem02.setAttribute("r", red)
            elem02.setAttribute("g", green)
            elem02.setAttribute("b", blue)

        FontId = 3
        for font in fonts:
            elem04 = out.createElement("font")
            elem03.appendChild(elem04)
            elem04.setAttribute("id", str(FontId))
            FontId += 1
            elem04.setAttribute("name", font)

        with open(name, 'wb') as f:
            f.write(out.toxml('utf-8'))