Пример #1
0
    def checkPair(self, g1, g2):
        """New checking method contributed by Frederik

        Returns a Boolean if overlapping.
        """

        kern = self.getKerning(g1, g2)
        
        # Check sidebearings first (PvB's idea)
        if self.rsb[g1] + self.lsb[g2] + kern > 0:
            return False

        # get the bounds and check them
        bounds1 = g1.box
        if bounds1 is None:
            return False
        bounds2 = g2.box
        if bounds2 is None:
            return False    

        # shift bounds2
        bounds2 = offsetRect(bounds2, g1.width+kern, 0)
        # check for intersection bounds
        intersectingBounds, _ = sectRect(bounds1, bounds2)
        if not intersectingBounds:
            return False
        # move bounds1 back, moving bounds is faster then moving all coordinates in a glyph
        bounds1 = offsetRect(bounds1, -g2.width-kern, 0)

        # create a pen for g1 with a shifted rect, draw the glyph into the pen
        pen1 = findPossibleOverlappingSegmentsPen.FindPossibleOverlappingSegmentsPen(g1.getParent(), bounds2)
        g1.draw(pen1)

        # create a pen for g2 with a shifted rect and move each found segment with the width and kerning
        pen2 = findPossibleOverlappingSegmentsPen.FindPossibleOverlappingSegmentsPen(g2.getParent(), bounds1, (g1.width+kern, 0))
        # draw the glyph into the pen
        g2.draw(pen2)

        for segment1 in pen1.segments:
            for segment2 in pen2.segments:
                if len(segment1) == 4 and len(segment2) == 4:
                    a1, a2, a3, a4 = segment1
                    b1, b2, b3, b4 = segment2
                    result = intersectCubicCubic(a1, a2, a3, a4, b1, b2, b3, b4)
                elif len(segment1) == 4:
                    p1, p2, p3, p4 = segment1
                    a1, a2 = segment2
                    result = intersectCubicLine(p1, p2, p3, p4, a1, a2)
                elif len(segment2) == 4:
                    p1, p2, p3, p4 = segment2
                    a1, a2 = segment1
                    result = intersectCubicLine(p1, p2, p3, p4, a1, a2)
                else:
                    a1, a2 = segment1
                    b1, b2 = segment2
                    result = intersectLineLine(a1, a2, b1, b2)
                if result.status == "Intersection":
                    return True

        return False
Пример #2
0
def makeLine(buf, font, y):
    line = buildGlyphLine(buf.glyph_infos, buf.glyph_positions,
                          font.glyphNames)

    rect = calcGlyphLineBounds(line, font)
    rect = offsetRect(rect, 0, y)

    ascender = font.ttFont["OS/2"].sTypoAscender
    descender = font.ttFont["OS/2"].sTypoDescender
    height = -ascender + descender

    return line, rect, height
Пример #3
0
def _bbox(f, gnames, points, scale=1):
    gset = f.glyphSet
    bbox = (0, 0, 0, 0)
    for i, gname in enumerate(gnames):
        if hasattr(points, '__len__') and i == len(points):
            points.append((bbox[2] / scale, 0))
        pt = points[i] if i < len(points) else (0, 0)
        g = gset[gname]._glyph
        if g is None or not hasattr(g, 'xMin'):
            gbox = (0, 0, 0, 0)
        else:
            gbox = (g.xMin * scale, g.yMin * scale, g.xMax * scale,
                    g.yMax * scale)
        bbox = arrayTools.unionRect(
            bbox, arrayTools.offsetRect(gbox, pt[0] * scale, pt[1] * scale))
    return bbox
Пример #4
0
    def checkPair(self, g1, g2):
        """New checking method contributed by Frederik

        Returns a Boolean if overlapping.
        """
        kern = g1._layer.rightKerningForLayer_(g2._layer)
        if kern > 10000:
            kern = 0
        # Check sidebearings first (PvB's idea)
        if self.rsb[g1] + self.lsb[g2] + kern > 0:
            return False

        # get the bounds and check them
        bounds1 = g1.box
        if bounds1 is None:
            return False
        bounds2 = g2.box
        if bounds2 is None:
            return False

        bounds2 = offsetRect(bounds2, g1.width + kern, 0)
        # check for intersection bounds
        intersectingBounds, _ = sectRect(bounds1, bounds2)
        if not intersectingBounds:
            return False

        # create a pen for g1 with a shifted rect, draw the glyph into the pen
        pen1 = self.penCache.get(g1.name, None)
        if not pen1:
            pen1 = SegmentsPen.SegmentsPen(self.font)
            g1.draw(pen1)
            self.penCache[g1.name] = pen1

        # create a pen for g2 with a shifted rect and move each found segment with the width and kerning

        pen2 = self.penCache.get(g2.name, None)
        if not pen2:
            pen2 = SegmentsPen.SegmentsPen(self.font)
            g2.draw(pen2)
            self.penCache[g2.name] = pen2

        offset = g1.width + kern

        for segment1 in pen1.segments:
            if not segmentInBound(segment1, bounds2):
                continue

            for segment2 in pen2.segments:
                segment2 = [(p[0] + offset, p[1]) for p in segment2]
                if not segmentInBound(segment2, bounds1):
                    continue
                if len(segment1) == 4 and len(segment2) == 4:
                    a1, a2, a3, a4 = segment1
                    b1, b2, b3, b4 = segment2
                    result = GSIntersectBezier3Bezier3(a1, a2, a3, a4, b1, b2,
                                                       b3, b4)
                elif len(segment1) == 4:
                    p1, p2, p3, p4 = segment1
                    a1, a2 = segment2
                    result = GSIntersectBezier3Line(p1, p2, p3, p4, a1, a2)
                elif len(segment2) == 4:
                    p1, p2, p3, p4 = segment2
                    a1, a2 = segment1
                    result = GSIntersectBezier3Line(p1, p2, p3, p4, a1, a2)
                else:
                    a1, a2 = segment1
                    b1, b2 = segment2
                    result = GSIntersectLineLine(a1, a2, b1, b2)
                    result = result.x < 100000
                if result:
                    return True
        return False
Пример #5
0
    def checkPair(self, g1, g2):
        """New checking method contributed by Frederik

        Returns a Boolean if overlapping.
        """
        kern = g1._layer.rightKerningForLayer_(g2._layer)
        if kern > 10000:
            kern = 0
        # Check sidebearings first (PvB's idea)
        if self.rsb[g1] + self.lsb[g2] + kern > 0:
            return False

        # get the bounds and check them
        bounds1 = g1.box
        if bounds1 is None:
            return False
        bounds2 = g2.box
        if bounds2 is None:
            return False

        bounds2 = offsetRect(bounds2, g1.width+kern, 0)
        # check for intersection bounds
        intersectingBounds, _ = sectRect(bounds1, bounds2)
        if not intersectingBounds:
            return False

        # create a pen for g1 with a shifted rect, draw the glyph into the pen
        pen1 = self.penCache.get(g1.name, None)
        if not pen1:
            pen1 = SegmentsPen.SegmentsPen(self.font)
            g1.draw(pen1)
            self.penCache[g1.name] = pen1
        
        # create a pen for g2 with a shifted rect and move each found segment with the width and kerning
        
        pen2 = self.penCache.get(g2.name, None)
        if not pen2:
            pen2 = SegmentsPen.SegmentsPen(self.font)
            g2.draw(pen2)
            self.penCache[g2.name] = pen2
        
        offset = g1.width+kern
        
        for segment1 in pen1.segments:
            if not segmentInBound(segment1, bounds2):
                continue
            
            for segment2 in pen2.segments:
                segment2 = [(p[0] + offset, p[1]) for p in segment2]
                if not segmentInBound(segment2, bounds1):
                    continue
                if len(segment1) == 4 and len(segment2) == 4:
                    a1, a2, a3, a4 = segment1
                    b1, b2, b3, b4 = segment2
                    result = GSIntersectBezier3Bezier3(a1, a2, a3, a4, b1, b2, b3, b4)
                elif len(segment1) == 4:
                    p1, p2, p3, p4 = segment1
                    a1, a2 = segment2
                    result = GSIntersectBezier3Line(p1, p2, p3, p4, a1, a2)
                elif len(segment2) == 4:
                    p1, p2, p3, p4 = segment2
                    a1, a2 = segment1
                    result = GSIntersectBezier3Line(p1, p2, p3, p4, a1, a2)
                else:
                    a1, a2 = segment1
                    b1, b2 = segment2
                    result = GSIntersectLineLine(a1, a2, b1, b2)
                    result = result.x < 100000
                if result:
                    return True
        return False
Пример #6
0
def test_offsetRect():
    assert offsetRect((10, 20, 30, 40), 5, 6) == (15, 26, 35, 46)
Пример #7
0
def test_offsetRect():
    assert offsetRect((10, 20, 30, 40), 5, 6) == (15, 26, 35, 46)
Пример #8
0
    def checkPair(self, g1, g2):
        """New checking method contributed by Frederik

        Returns a Boolean if overlapping.
        """

        kern = self.getKerning(g1, g2)

        # Check sidebearings first (PvB's idea)
        if self.rsb[g1] + self.lsb[g2] + kern > 0:
            return False

        # get the bounds and check them
        bounds1 = g1.box
        if bounds1 is None:
            return False
        bounds2 = g2.box
        if bounds2 is None:
            return False

        # shift bounds2
        bounds2 = offsetRect(bounds2, g1.width + kern, 0)
        # check for intersection bounds
        intersectingBounds, _ = sectRect(bounds1, bounds2)
        if not intersectingBounds:
            return False
        # move bounds1 back, moving bounds is faster then moving all coordinates in a glyph
        bounds1 = offsetRect(bounds1, -g2.width - kern, 0)

        # create a pen for g1 with a shifted rect, draw the glyph into the pen
        pen1 = findPossibleOverlappingSegmentsPen.FindPossibleOverlappingSegmentsPen(
            g1.getParent(), bounds2)
        g1.draw(pen1)

        # create a pen for g2 with a shifted rect and move each found segment with the width and kerning
        pen2 = findPossibleOverlappingSegmentsPen.FindPossibleOverlappingSegmentsPen(
            g2.getParent(), bounds1, (g1.width + kern, 0))
        # draw the glyph into the pen
        g2.draw(pen2)

        for segment1 in pen1.segments:
            for segment2 in pen2.segments:
                if len(segment1) == 4 and len(segment2) == 4:
                    a1, a2, a3, a4 = segment1
                    b1, b2, b3, b4 = segment2
                    result = intersectCubicCubic(a1, a2, a3, a4, b1, b2, b3,
                                                 b4)
                elif len(segment1) == 4:
                    p1, p2, p3, p4 = segment1
                    a1, a2 = segment2
                    result = intersectCubicLine(p1, p2, p3, p4, a1, a2)
                elif len(segment2) == 4:
                    p1, p2, p3, p4 = segment2
                    a1, a2 = segment1
                    result = intersectCubicLine(p1, p2, p3, p4, a1, a2)
                else:
                    a1, a2 = segment1
                    b1, b2 = segment2
                    result = intersectLineLine(a1, a2, b1, b2)
                if result.status == "Intersection":
                    return True

        return False
Пример #9
0
def checkIfPairOverlaps(g1, g2):
    assert g1.getParent() is g2.getParent(), 'the two glyphs do not belong to the same font'

    """Checking method from Touche!
    Returns a Boolean if overlapping.
    """

    kern = g1.getParent().naked().flatKerning.get((g1.name, g2.name), 0)

    # Check sidebearings first (PvB's idea)
    if g1.rightMargin + g2.leftMargin + kern > 0:
        return False

    # get the bounds and check them
    if version[0] == '2':
        bounds1 = g1.bounds
    else:
        bounds1 = g1.box
    if bounds1 is None:
        return False
    if version[0] == '2':
        bounds2 = g2.bounds
    else:
        bounds2 = g2.box
    if bounds2 is None:
        return False

    # shift bounds2
    bounds2 = offsetRect(bounds2, g1.width+kern, 0)
    # check for intersection bounds
    intersectingBounds, _ = sectRect(bounds1, bounds2)
    if not intersectingBounds:
        return False
    # move bounds1 back, moving bounds is faster then moving all coordinates in a glyph
    bounds1 = offsetRect(bounds1, -g2.width-kern, 0)

    # create a pen for g1 with a shifted rect, draw the glyph into the pen
    pen1 = FindPossibleOverlappingSegmentsPen(g1.getParent(), bounds2)
    g1.draw(pen1)

    # create a pen for g2 with a shifted rect and move each found segment with the width and kerning
    pen2 = FindPossibleOverlappingSegmentsPen(g2.getParent(), bounds1, (g1.width+kern, 0))
    # draw the glyph into the pen
    g2.draw(pen2)

    for segment1 in pen1.segments:
        for segment2 in pen2.segments:
            if len(segment1) == 4 and len(segment2) == 4:
                a1, a2, a3, a4 = segment1
                b1, b2, b3, b4 = segment2
                result = intersectCubicCubic(a1, a2, a3, a4, b1, b2, b3, b4)
            elif len(segment1) == 4:
                p1, p2, p3, p4 = segment1
                a1, a2 = segment2
                result = intersectCubicLine(p1, p2, p3, p4, a1, a2)
            elif len(segment2) == 4:
                p1, p2, p3, p4 = segment2
                a1, a2 = segment1
                result = intersectCubicLine(p1, p2, p3, p4, a1, a2)
            else:
                a1, a2 = segment1
                b1, b2 = segment2
                result = intersectLineLine(a1, a2, b1, b2)
            if result.status == "Intersection":
                return True

    return False