<commit_before># -*- coding: utf-8 -*-
"""
Written by <NAME>.
Email: danaukes<at>seas.harvard.edu.
Please see LICENSE.txt for full license.
"""

import PySide.QtCore as qc
import PySide.QtGui as qg
import numpy
from popupcad.graphics2d.graphicsitems import Common
import popupcad 
from popupcad.geometry.vertex import ShapeVertex
class GenericText(object):
    editable = ['*']
    deletable = ['*']    
    hidden = ['id']
    
    def __init__(self,text,pos,font = 'Arial',fontsize = 1):
        self.text = text
        self.pos = pos
        self.font = font
        self.fontsize = fontsize
        self.exteriors = []
        self.id  = id(self)
    def copy(self,identical=True):
        new = type(self)(self.text,self.pos,self.font, self.fontsize)
        if identical:
            new.id = self.id
        return new
    def isValid(self):
        return True
    def genpath(self):
        text = self.text
        p = qg.QPainterPath()
        
        font = qg.QFont(self.font, pointSize=self.fontsize*popupcad.internal_argument_scaling)
        p.addText(qc.QPointF(0,1*self.fontsize*popupcad.internal_argument_scaling),font,text)

        p2 = qg.QPainterPath()
        exteriors = []     
        exterior = None
        for ii in range(p.elementCount()):
            element = p.elementAt(ii)
            if element.isMoveTo():
                if exterior!=None:
                    p2.lineTo(exterior[0][0],exterior[0][1])
                    exteriors.append(exterior)
                exterior = [(element.x,-element.y)]
                p2.moveTo(element.x,-element.y)
            elif element.isLineTo():
                p2.lineTo(element.x,-element.y)
                exterior.append((element.x,-element.y))
            elif element.isCurveTo():
                p2.lineTo(element.x,-element.y)
                exterior.append((element.x,-element.y))

        if exterior!=None:
            exteriors.append(exterior)
        exteriors = [(numpy.array(exterior)+self.pos.getpos()).tolist() for exterior in exteriors]
        self.exteriors_p = exteriors
        self.exteriors = self.buildvertices(exteriors)
        self.path = p2
        return p2
        
    def buildvertices(self,exteriors_p):
        exteriors = [[ShapeVertex(pos) for pos in exterior_p] for exterior_p in exteriors_p]
        return exteriors
        
    def outputinteractive(self):
        tp = TextParent(self)
        return tp
        
    def outputshapely(self):
        import popupcad.geometry.customshapely as customshapely
        import shapely.ops as so<commit_msg>little bugfix<commit_after># -*- coding: utf-8 -*-
"""
Written by <NAME>.
Email: <EMAIL><at><EMAIL>.har<EMAIL>.
Please see LICENSE.txt for full license.
"""

import PySide.QtCore as qc
import PySide.QtGui as qg
import numpy
from popupcad.graphics2d.graphicsitems import Common
import popupcad 
from popupcad.geometry.vertex import ShapeVertex
class GenericText(object):
    editable = ['*']
    deletable = ['*']    
    hidden = ['id']
    
    def __init__(self,text,pos,font = 'Arial',fontsize = 1):
        self.text = text
        self.pos = pos
        self.font = font
        self.fontsize = fontsize
        self.exteriors = []
        self.id  = id(self)
    def copy(self,identical=True):
        new = type(self)(self.text,self.pos,self.font, self.fontsize)
        if identical:
            new.id = self.id
        return new
    def isValid(self):
        return True
    def genpath(self):
        text = self.text
        p = qg.QPainterPath()
        
        font = qg.QFont(self.font, pointSize=self.fontsize*popupcad.internal_argument_scaling)
        p.addText(qc.QPointF(0,1*self.fontsize*popupcad.internal_argument_scaling),font,text)

        p2 = qg.QPainterPath()
        exteriors = []     
        exterior = None
        for ii in range(p.elementCount()):
            element = p.elementAt(ii)
            if element.isMoveTo():
                if exterior!=None:
                    p2.lineTo(exterior[0][0],exterior[0][1])
                    exteriors.append(exterior)
                exterior = [(element.x,-element.y)]
                p2.moveTo(element.x,-element.y)
            elif element.isLineTo():
                p2.lineTo(element.x,-element.y)
                exterior.append((element.x,-element.y))
            elif element.isCurveTo():
                p2.lineTo(element.x,-element.y)
                exterior.append((element.x,-element.y))

        if exterior!=None:
            exteriors.append(exterior)
        exteriors = [(numpy.array(exterior)+self.pos.getpos()).tolist() for exterior in exteriors]
        self.exteriors_p = exteriors
        self.exteriors = self.buildvertices(exteriors)
        self.path = p2
        return p2
        
    def buildvertices(self,exteriors_p):
        exteriors = [[ShapeVertex(pos) for pos in exterior_p] for exterior_p in exteriors_p]
        return exteriors
        
    def outputinteractive(self):
        tp = TextParent(self)
        return tp
        
    def outputshapely(self):
        import popupcad.geometry.customshapely as customshapely
        import shapely.ops as so
        self.genpath()
{'fraction_non_alphanumeric': 0.11287205257054503, 'fraction_numerical': 0.006184770003865481, 'mean_word_length': 2.096947935368043, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '895903', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1603, 'n_words': 311}