Exemplo n.º 1
0
 def parse_valuerecord_(self, vertical):
     if self.next_token_type_ is Lexer.NUMBER:
         number, location = self.expect_number_(), self.cur_token_location_
         if vertical:
             val = ast.ValueRecord(location, 0, 0, 0, number)
         else:
             val = ast.ValueRecord(location, 0, 0, number, 0)
         return val
     self.expect_symbol_("<")
     location = self.cur_token_location_
     if self.next_token_type_ is Lexer.NAME:
         name = self.expect_name_()
         vrd = self.valuerecords_.resolve(name)
         if vrd is None:
             raise FeatureLibError("Unknown valueRecordDef \"%s\"" % name,
                                   self.cur_token_location_)
         value = vrd.value
         xPlacement, yPlacement = (value.xPlacement, value.yPlacement)
         xAdvance, yAdvance = (value.xAdvance, value.yAdvance)
     else:
         xPlacement, yPlacement, xAdvance, yAdvance = (
             self.expect_number_(), self.expect_number_(),
             self.expect_number_(), self.expect_number_())
     self.expect_symbol_(">")
     return ast.ValueRecord(location, xPlacement, yPlacement, xAdvance,
                            yAdvance)
Exemplo n.º 2
0
    def parse_valuerecord_(self, vertical):
        if self.next_token_type_ is Lexer.NUMBER:
            number, location = self.expect_number_(), self.cur_token_location_
            if vertical:
                val = ast.ValueRecord(location, 0, 0, 0, number,
                                      None, None, None, None)
            else:
                val = ast.ValueRecord(location, 0, 0, number, 0,
                                      None, None, None, None)
            return val
        self.expect_symbol_("<")
        location = self.cur_token_location_
        if self.next_token_type_ is Lexer.NAME:
            name = self.expect_name_()
            if name == "NULL":
                self.expect_symbol_(">")
                return None
            vrd = self.valuerecords_.resolve(name)
            if vrd is None:
                raise FeatureLibError("Unknown valueRecordDef \"%s\"" % name,
                                      self.cur_token_location_)
            value = vrd.value
            xPlacement, yPlacement = (value.xPlacement, value.yPlacement)
            xAdvance, yAdvance = (value.xAdvance, value.yAdvance)
        else:
            xPlacement, yPlacement, xAdvance, yAdvance = (
                self.expect_number_(), self.expect_number_(),
                self.expect_number_(), self.expect_number_())

        if self.next_token_ == "<":
            xPlaDevice, yPlaDevice, xAdvDevice, yAdvDevice = (
                self.parse_device_(), self.parse_device_(),
                self.parse_device_(), self.parse_device_())
            allDeltas = sorted([
                delta
                for size, delta
                in (xPlaDevice if xPlaDevice else ()) +
                (yPlaDevice if yPlaDevice else ()) +
                (xAdvDevice if xAdvDevice else ()) +
                (yAdvDevice if yAdvDevice else ())])
            if allDeltas[0] < -128 or allDeltas[-1] > 127:
                raise FeatureLibError(
                    "Device value out of valid range (-128..127)",
                    self.cur_token_location_)
        else:
            xPlaDevice, yPlaDevice, xAdvDevice, yAdvDevice = (
                None, None, None, None)

        self.expect_symbol_(">")
        return ast.ValueRecord(
            location, xPlacement, yPlacement, xAdvance, yAdvance,
            xPlaDevice, yPlaDevice, xAdvDevice, yAdvDevice)
Exemplo n.º 3
0
    def _adjustment(self, adjustment):
        adv, dx, dy, adv_adjust_by, dx_adjust_by, dy_adjust_by = adjustment

        adv_device = adv_adjust_by and adv_adjust_by.items() or None
        dx_device = dx_adjust_by and dx_adjust_by.items() or None
        dy_device = dy_adjust_by and dy_adjust_by.items() or None

        return ast.ValueRecord(
            xPlacement=dx,
            yPlacement=dy,
            xAdvance=adv,
            xPlaDevice=dx_device,
            yPlaDevice=dy_device,
            xAdvDevice=adv_device,
        )
Exemplo n.º 4
0
 def test_valuerecord_none(self):
     statement = ast.ValueRecord(xPlacement=10, xAdvance=20)
     self.assertEqual(statement.asFea(), "<10 0 20 0>")