Ejemplo n.º 1
0
def add_stroke_attr(glyph):
    """ Adds stroke attribute at first point of the glyph.

    The stroke attribute indicates that the point is the start or end point
    when drawing the letter. The key of stroke attribute is 'stroke' and the
    value is 'begin' or 'end'. This attribute depends on 'double', 'char' and
    'sound' attribute so make sure that these attributes are already inside
    the glyph before calling this function.

    Args:
        glyph:: RGlyph
            The RGlyph object that you want to add stroke attribute.
    """
    repr_point = at.name2dict(glyph.contours[0].points[0].name)
    if repr_point.get('double') is not None:
        for contour in glyph.contours:
            attr = at.name2dict(contour.points[0].name)
            char = int(attr.get('char'))
            sound = attr.get('sound')
            if (sound == 'first' and (char == 1 or char == 4)) or \
                    (sound == 'final' and char in (2, 3, 5, 6, *range(9, 16), 18)):
                contour_set = _classify_contours(glyph)
                contour_set = [
                    _get_stroke_dict(contours) for contours in contour_set
                ]
            else:
                contour_set = [_get_stroke_dict(glyph.contours)]
    else:
        contour_set = [_get_stroke_dict(glyph.contours)]
    for stroke_dict in contour_set:
        if stroke_dict:
            for stroke, points in stroke_dict.items():
                for point in points:
                    at.add_attr(point, 'stroke', stroke)
def add_elem_attr(glyph):
    """ Adds elem attribute to RGlyph object. """
    for contour in glyph.contours:
        is_stem = True
        for point in contour.points:
            if point.type == 'offcurve':
                continue
            if _is_inside_point(glyph, point):
                is_stem = False
                break
        if is_stem:
            at.add_attr(contour.points[0], 'elem', 'stem')
        else:
            at.add_attr(contour.points[0], 'elem', 'branch')
    def giveDependY(self):
        """
        dependy 속성을 추가함
        """
        if self.cCheckCon == None:
            raise Exception('Please executed topologyJudgement method')

        l1 = self.sCheckCon.tpPointList
        l2 = self.cCheckCon.tpPointList

        for i in range(0, len(l1)):
            if (l1[i].point.selected == True):
                temp = at.get_attr(l1[i].point, 'dependY')
                at.add_attr(l2[i].point, 'dependY', temp)
    def giveAttrPenPair(self):
        """
        penpair 속성을 추가함
        """
        if self.cCheckCon == None:
            raise Exception('Please executed topologyJudgement method')

        l1 = self.sCheckCon.tpPointList
        l2 = self.cCheckCon.tpPointList

        for i in range(0, len(l1)):
            if (l1[i].point.selected == True):
                temp = at.get_attr(l1[i].point, 'penPair')
                print(temp)
                at.add_attr(l2[i].point, 'penPair', temp)
Ejemplo n.º 5
0
def add_depend_attr(glyph):
    """ Adds depend attribute at points of the glyph.

    The depend attribute indicates that certain points move in dependence on
    other points to maintain their shape while the letter is transformed.
    The key of depend attribute is 'dependX' or 'dependY' and the value is
    penPair attribute value(ex.'z1r'). The points with the depend attribute
    move as the dependent values move.

    Args:
        glyph:: RGlyph
            The RGlyph object that you want to add depend attribute.
    Raises:
        type of variable error:: TypeError
            If TypeError occurred, passes that case.
    """
    penpair_dict = at.get_penpair_dict(glyph)
    all_points = chain(*penpair_dict.values())
    for contour in glyph.contours:
        for i, current_point in enumerate(contour.points):
            previous_point = contour.points[i - 1]
            try:
                if previous_point not in penpair_dict[at.get_attr(
                        current_point, 'penPair')[1:-1]]:
                    continue
                target_point = _find_depend_target(current_point, penpair_dict,
                                                   all_points)
                if target_point:
                    attribute_name = ""
                    if abs(current_point.x - previous_point.x) < 5:
                        attribute_name = 'dependX'
                    elif abs(current_point.y - previous_point.y) < 5:
                        attribute_name = 'dependY'
                    if attribute_name:
                        at.add_attr(current_point, attribute_name,
                                    at.get_attr(target_point, 'penPair'))
                        at.add_attr(previous_point, attribute_name,
                                    at.get_attr(target_point, 'penPair'))
                        glyph.setChanged()
            except TypeError:
                continue
Ejemplo n.º 6
0
 def mgiveStroke(self, matchPoint):
     if matchPoint is not None:
         temp = at.get_attr(self.point, 'stroke')
         if temp is not None:
             at.add_attr(matchPoint, 'stroke', temp)
Ejemplo n.º 7
0
 def mgiveInnerFill(self, matchPoint):
     if matchPoint is not None:
         temp = at.get_attr(self.point, 'innerType')
         if temp is not None:
             at.add_attr(matchPoint, 'innerType', temp)
Ejemplo n.º 8
0
 def mgiveDependY(self, matchPoint):
     if matchPoint is not None:
         temp = at.get_attr(self.point, 'dependY')
         if temp is not None:
             at.add_attr(matchPoint, 'dependY', temp)
Ejemplo n.º 9
0
 def mgiveAttrPenPair(self, matchPoint):
     if matchPoint is not None:
         temp = at.get_attr(self.point, 'penPair')
         if temp is not None:
             at.add_attr(matchPoint, 'penPair', temp)
def add_round_attr(point):
    at.add_attr(point, "round", 1)