Пример #1
0
	def put_char(self, putset, h, v, fntnum, dvicode, color=None):
		try:
			glyph, glyphscale, hadv = font.get_char(fntnum, dvicode)
			assert glyph is not None, (fntnum, dvicode)
		except KeyError:
			return 0.0

		self.id.add( (fntnum, dvicode) )

		H  = self.scale * (h + self.oneinch)
		V  = self.scale * (v + self.oneinch)

		self.chars.append( (fntnum, dvicode, H, V, glyphscale, color, putset) )
		return hadv
Пример #2
0
    def put_char(self, putset, h, v, fntnum, dvicode, color=None):
        try:
            glyph, glyphscale, hadv = font.get_char(fntnum, dvicode)
            assert glyph is not None, (fntnum, dvicode)
        except KeyError:
            return 0.0

        self.id.add((fntnum, dvicode))

        H = self.scale * (h + self.oneinch)
        V = self.scale * (v + self.oneinch)

        self.chars.append((fntnum, dvicode, H, V, glyphscale, color, putset))
        return hadv
Пример #3
0
	def flush_glyphs(self):
		new = self.document.createElement

		elements = []
		for fntnum, dvicode in self.id:
			try:
				glyph, _, _ = font.get_char(fntnum, dvicode)
			except KeyError:
				continue

			path = new('path')
			path.setAttribute("id", "%02x%d" % (dvicode, fntnum))
			path.setAttribute("d",  glyph)
			elements.append(path)

		return elements
Пример #4
0
    def flush_glyphs(self):
        new = self.document.createElement

        elements = []
        for fntnum, dvicode in self.id:
            try:
                glyph, _, _ = font.get_char(fntnum, dvicode)
            except KeyError:
                continue

            path = new('path')
            path.setAttribute("id", "%02x%d" % (dvicode, fntnum))
            path.setAttribute("d", glyph)
            elements.append(path)

        return elements
Пример #5
0
	def get_page_bbox(self, element=None):
		"Returns bbox of chars (self.chars) and rules (self.reules)."

		new  = self.document.createElement
		X = []
		Y = []

		# bbox of chars
		for (fntnum, dvicode, H, V, glyphscale, color, _) in self.chars:
			try:
				bbox = self.bbox_cache[fntnum, dvicode]
			except KeyError:
				path   = font.get_char(fntnum, dvicode)[0]
				tokens = path_element.tokens(path)
				bbox   = path_element.bounding_box(tokens)
				self.bbox_cache[fntnum, dvicode] = bbox

			(xmin, ymin), (xmax, ymax) = bbox
			X.append(H+xmax*glyphscale)
			X.append(H+xmin*glyphscale)
			Y.append(V-ymax*glyphscale)
			Y.append(V-ymin*glyphscale)

			"""
			# blue background for char's bbox (TESTING)
			tmp = new('rect')
			tmp.setAttribute('fill',  '#aaf')
			tmp.setAttribute('x', str(H+xmax*glyphscale))
			tmp.setAttribute('y', str(V-ymax*glyphscale))
			tmp.setAttribute('width',  str(glyphscale * (xmin-xmax)))
			tmp.setAttribute('height', str(glyphscale * (ymax-ymin)))
			element.appendChild(tmp)
			"""

		# bbox of rules
		for (h,v, a, b, color) in self.rules:
			X.append(self.scale * (h + self.oneinch))
			X.append(self.scale * (h + self.oneinch + b))

			Y.append(self.scale * (v - a + self.oneinch))
			Y.append(self.scale * (v + self.oneinch))

		# get bbox
		xmin = min(X)
		xmax = max(X)

		ymin = min(Y)
		ymax = max(Y)

		"""
		# red frame around bbox (TESTING)
		tmp = new('rect')
		tmp.setAttribute("x", str(xmin))
		tmp.setAttribute("y", str(ymin))
		tmp.setAttribute("width",  str(xmax - xmin))
		tmp.setAttribute("height", str(ymax - ymin))
		tmp.setAttribute('fill',  'none')
		tmp.setAttribute('stroke','red')
		tmp.setAttribute('stroke-width', '2')
		element.appendChild(tmp)
		"""

		return xmin, ymin, xmax, ymax
Пример #6
0
    def get_page_bbox(self, element=None):
        "Returns bbox of chars (self.chars) and rules (self.reules)."

        new = self.document.createElement
        X = []
        Y = []

        # bbox of chars
        for (fntnum, dvicode, H, V, glyphscale, color, _) in self.chars:
            try:
                bbox = self.bbox_cache[fntnum, dvicode]
            except KeyError:
                path = font.get_char(fntnum, dvicode)[0]
                tokens = path_element.tokens(path)
                bbox = path_element.bounding_box(tokens)
                self.bbox_cache[fntnum, dvicode] = bbox

            (xmin, ymin), (xmax, ymax) = bbox
            X.append(H + xmax * glyphscale)
            X.append(H + xmin * glyphscale)
            Y.append(V - ymax * glyphscale)
            Y.append(V - ymin * glyphscale)
            """
			# blue background for char's bbox (TESTING)
			tmp = new('rect')
			tmp.setAttribute('fill',  '#aaf')
			tmp.setAttribute('x', str(H+xmax*glyphscale))
			tmp.setAttribute('y', str(V-ymax*glyphscale))
			tmp.setAttribute('width',  str(glyphscale * (xmin-xmax)))
			tmp.setAttribute('height', str(glyphscale * (ymax-ymin)))
			element.appendChild(tmp)
			"""

        # bbox of rules
        for (h, v, a, b, color) in self.rules:
            X.append(self.scale * (h + self.oneinch))
            X.append(self.scale * (h + self.oneinch + b))

            Y.append(self.scale * (v - a + self.oneinch))
            Y.append(self.scale * (v + self.oneinch))

        # get bbox
        xmin = min(X)
        xmax = max(X)

        ymin = min(Y)
        ymax = max(Y)
        """
		# red frame around bbox (TESTING)
		tmp = new('rect')
		tmp.setAttribute("x", str(xmin))
		tmp.setAttribute("y", str(ymin))
		tmp.setAttribute("width",  str(xmax - xmin))
		tmp.setAttribute("height", str(ymax - ymin))
		tmp.setAttribute('fill',  'none')
		tmp.setAttribute('stroke','red')
		tmp.setAttribute('stroke-width', '2')
		element.appendChild(tmp)
		"""

        return xmin, ymin, xmax, ymax