示例#1
0
def _find_depend_target(point, penpair_dict, point_list):
    pair_points = penpair_dict[at.get_attr(point, 'penPair')[1:-1]]
    for target_point in point_list:
        target_pair_points = penpair_dict[at.get_attr(target_point,
                                                      'penPair')[1:-1]]
        if _is_between(pair_points, target_point) and \
                _is_diff_direction(pair_points, target_pair_points):
            return target_point
    return None
示例#2
0
def _get_penpair_dict(contour):
    penpair_dict = {}
    all_points = _get_all_points(contour)
    for point in all_points:
        penpair = at.get_attr(point, 'penPair')[1:-1]
        if penpair in penpair_dict:
            penpair_dict[penpair].append(point)
        else:
            penpair_dict[penpair] = [point]
    return penpair_dict
def _classify_contours(glyph):
    classified_dict = {}
    for contour in glyph.contours:
        double = at.get_attr(contour.points[0], 'double')
        if double is not None:
            try:
                classified_dict[double].append(contour)
            except KeyError:
                classified_dict[double] = [contour]
    return tuple(classified_dict.values())
示例#4
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
def _get_stroke_dict(contours):
    stroke_dict = {'begin': [], 'end': []}
    criteria_1 = lambda p: at.get_attr(p, 'dependX') is None and \
                           at.get_attr(p, 'dependY') is None
    criteria_2 = lambda p: any([
        contour.pointInside(p.position) for contour in contours
        if not contour is p.contour
    ])
    candidates = []
    for contour in contours:
        try:
            penpair_dict = _get_penpair_dict(contour)
        except _PairError:
            continue
        stroke_parts = []
        for penpair, points in penpair_dict.items():
            idx_diff = abs(points[0].index - points[1].index)
            if len(points) == 2 and (idx_diff == 1
                                     or idx_diff == len(contour.points) - 1):
                stroke_parts.append(points)
        if len(stroke_parts) == 2:
            candidates.append(stroke_parts)
    for candidate in candidates:
        cand_1, cand_2 = candidate
        if (cand_1[0].y + cand_1[1].y) / 2 > (cand_2[0].y + cand_2[1].y) / 2:
            if all(map(criteria_1,
                       cand_1)) and not any(map(criteria_2, cand_1)):
                stroke_dict['begin'].extend(cand_1)
            if all(map(criteria_1,
                       cand_2)) and not any(map(criteria_2, cand_2)):
                stroke_dict['end'].extend(cand_2)
        else:
            if all(map(criteria_1,
                       cand_2)) and not any(map(criteria_2, cand_2)):
                stroke_dict['begin'].extend(cand_2)
            if all(map(criteria_1,
                       cand_1)) and not any(map(criteria_2, cand_1)):
                stroke_dict['end'].extend(cand_1)
    return stroke_dict
def _get_penpair_dict(contour):
    penpair_dict = {}
    for point in contour.points:
        if point.type == 'offcurve':
            continue
        penpair = at.get_attr(point, 'penPair')[1:-1]
        if penpair in penpair_dict:
            penpair_dict[penpair].append(point)
        else:
            penpair_dict[penpair] = [point]
    if not all(map(lambda x: len(x) == 2, penpair_dict.values())):
        raise _PairError('Pair is not exist.')
    return penpair_dict
    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)
示例#9
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)
示例#10
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)
示例#11
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)
示例#12
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)
示例#13
0
def _get_penpair_values(contour):
    return [int(at.get_attr(point, 'penPair')[1:-1]) for point in contour.points \
                                                     if point.type != 'offcurve']