예제 #1
0
def isWordBreakAfter(glyphNames, index, reversedCMAP):
    """
    Returns a boolean declaring if the position
    after index can be considered a word break.
    """
    # End of line
    if index == len(glyphNames) - 1:
        return True
    # get the unicode values and word break properties
    # for the previous, current and next two glyphs.
    unicodeValue = reversedCMAP.get(glyphNames[index], [None])[0]
    wordBreakProperty = wordBreakProperties.get(unicodeValue)
    forwardOneUnicodeValue = reversedCMAP.get(glyphNames[index + 1], [None])[0]
    forwardOneWordBreakProperty = wordBreakProperties.get(
        forwardOneUnicodeValue)
    if index > 0:
        backOneUnicodeValue = reversedCMAP.get(glyphNames[index - 1],
                                               [None])[0]
        backOneWordBreakProperty = wordBreakProperties.get(backOneUnicodeValue)
    else:
        backOneUnicodeValue = None
        backOneWordBreakProperty = None
    if index < len(glyphNames) - 2:
        forwardTwoUnicodeValue = reversedCMAP.get(glyphNames[index + 2],
                                                  [None])[0]
        forwardTwoWordBreakProperty = wordBreakProperties.get(
            forwardTwoUnicodeValue)
    else:
        forwardTwoUnicodeValue = None
        forwardTwoWordBreakProperty = None
    # test the current and next unicode values
    if (unicodeValue, forwardOneUnicodeValue) in _notBreakAfter:
        return False
    # test the current and next word break properties
    if (wordBreakProperty, forwardOneWordBreakProperty) in _notBreakAfter:
        return False
    # test the previous, current and next word break properties
    if (backOneWordBreakProperty, wordBreakProperty,
            forwardOneWordBreakProperty) in _notBreakAfter:
        return False
    # test the current and next two word break properties
    if (wordBreakProperty, forwardOneWordBreakProperty,
            forwardTwoWordBreakProperty) in _notBreakAfter:
        return False
    # Otherwise, break everywhere (including around ideographs).
    return True
예제 #2
0
def isWordBreakBefore(glyphNames, index, reversedCMAP):
    """
    Returns a boolean declaring if the position
    before index can be considered a word break.
    """
    # Start of line
    if index == 0:
        return True
    # get the unicode values and word break properties
    # for the previous two, current and next glyphs.
    unicodeValue = reversedCMAP.get(glyphNames[index], [None])[0]
    wordBreakProperty = wordBreakProperties.get(unicodeValue)
    backOneUnicodeValue = reversedCMAP.get(glyphNames[index - 1], [None])[0]
    backOneWordBreakProperty = wordBreakProperties.get(backOneUnicodeValue)
    if index > 1:
        backTwoUnicodeValue = reversedCMAP.get(glyphNames[index - 2],
                                               [None])[0]
        backTwoWordBreakProperty = wordBreakProperties.get(backTwoUnicodeValue)
    else:
        backTwoUnicodeValue = False
        backTwoWordBreakProperty = False
    if index < len(glyphNames) - 1:
        forwardOneUnicodeValue = reversedCMAP.get(glyphNames[index + 1],
                                                  [None])[0]
        forwardOneWordBreakProperty = wordBreakProperties.get(
            forwardOneUnicodeValue)
    else:
        forwardOneUnicodeValue = None
        forwardOneWordBreakProperty = None
    # test the previous and current unicode values
    if (backOneUnicodeValue, unicodeValue) in _notBreakBefore:
        return False
    # test the previous and current word break properties
    if (backOneWordBreakProperty, wordBreakProperty) in _notBreakBefore:
        return False
    # test the previous, current and next word break properties
    if (backOneWordBreakProperty, wordBreakProperty,
            forwardOneWordBreakProperty) in _notBreakBefore:
        return False
    # test the previous, current and next word break properties
    if (backTwoWordBreakProperty, backOneWordBreakProperty,
            wordBreakProperty) in _notBreakBefore:
        return False
    # Otherwise, break everywhere (including around ideographs).
    return True
예제 #3
0
def isWordBreakAfter(glyphNames, index, reversedCMAP):
    """
    Returns a boolean declaring if the position
    after index can be considered a word break.
    """
    # End of line
    if index == len(glyphNames) - 1:
        return True
    # get the unicode values and word break properties
    # for the previous, current and next two glyphs.
    unicodeValue = reversedCMAP.get(glyphNames[index], [None])[0]
    wordBreakProperty = wordBreakProperties.get(unicodeValue)
    forwardOneUnicodeValue = reversedCMAP.get(glyphNames[index + 1], [None])[0]
    forwardOneWordBreakProperty = wordBreakProperties.get(forwardOneUnicodeValue)
    if index > 0:
        backOneUnicodeValue = reversedCMAP.get(glyphNames[index - 1], [None])[0]
        backOneWordBreakProperty = wordBreakProperties.get(backOneUnicodeValue)
    else:
        backOneUnicodeValue = None
        backOneWordBreakProperty = None
    if index < len(glyphNames) - 2:
        forwardTwoUnicodeValue = reversedCMAP.get(glyphNames[index + 2], [None])[0]
        forwardTwoWordBreakProperty = wordBreakProperties.get(forwardTwoUnicodeValue)
    else:
        forwardTwoUnicodeValue = None
        forwardTwoWordBreakProperty = None
    # test the current and next unicode values
    if (unicodeValue, forwardOneUnicodeValue) in _notBreakAfter:
        return False
    # test the current and next word break properties
    if (wordBreakProperty, forwardOneWordBreakProperty) in _notBreakAfter:
        return False
    # test the previous, current and next word break properties
    if (backOneWordBreakProperty, wordBreakProperty, forwardOneWordBreakProperty) in _notBreakAfter:
        return False
    # test the current and next two word break properties
    if (wordBreakProperty, forwardOneWordBreakProperty, forwardTwoWordBreakProperty) in _notBreakAfter:
        return False
    # Otherwise, break everywhere (including around ideographs).
    return True
예제 #4
0
def isWordBreakBefore(glyphNames, index, reversedCMAP):
    """
    Returns a boolean declaring if the position
    before index can be considered a word break.
    """
    # Start of line
    if index == 0:
        return True
    # get the unicode values and word break properties
    # for the previous two, current and next glyphs.
    unicodeValue = reversedCMAP.get(glyphNames[index], [None])[0]
    wordBreakProperty = wordBreakProperties.get(unicodeValue)
    backOneUnicodeValue = reversedCMAP.get(glyphNames[index - 1], [None])[0]
    backOneWordBreakProperty = wordBreakProperties.get(backOneUnicodeValue)
    if index > 1:
        backTwoUnicodeValue = reversedCMAP.get(glyphNames[index - 2], [None])[0]
        backTwoWordBreakProperty = wordBreakProperties.get(backTwoUnicodeValue)
    else:
        backTwoUnicodeValue = False
        backTwoWordBreakProperty = False
    if index < len(glyphNames) - 1:
        forwardOneUnicodeValue = reversedCMAP.get(glyphNames[index + 1], [None])[0]
        forwardOneWordBreakProperty = wordBreakProperties.get(forwardOneUnicodeValue)
    else:
        forwardOneUnicodeValue = None
        forwardOneWordBreakProperty = None
    # test the previous and current unicode values
    if (backOneUnicodeValue, unicodeValue) in _notBreakBefore:
        return False
    # test the previous and current word break properties
    if (backOneWordBreakProperty, wordBreakProperty) in _notBreakBefore:
        return False
    # test the previous, current and next word break properties
    if (backOneWordBreakProperty, wordBreakProperty, forwardOneWordBreakProperty) in _notBreakBefore:
        return False
    # test the previous, current and next word break properties
    if (backTwoWordBreakProperty, backOneWordBreakProperty, wordBreakProperty) in _notBreakBefore:
        return False
    # Otherwise, break everywhere (including around ideographs).
    return True