Exemple #1
0
    def instantiate(self):
        if not self.font:
            color = resolve_color(self.color)
            self.font = imlib2.load_font(self.name, self.size)

            if self.font:
                self.font.set_color(color)
Exemple #2
0
    def get_font(self):
        color = self.get_theme().get_color(self.color)
        font = imlib2.load_font(self.font, self.size)
        if font:
            font.set_color(color)

        return font
Exemple #3
0
    def instantiate(self):
        if not self.font:
            color = resolve_color(self.color)
            self.font = imlib2.load_font(self.name, self.size)

            if self.font:
                self.font.set_color(color)
Exemple #4
0
    def _sync_property_font(self):
        old_size = self._o.geometry_get()[1]

        font_name = self["font"][0]
        font_size = self._get_computed_font_size()

        if self._o.type_get() == "image":
            self._font = imlib2.load_font(font_name, font_size)
            self._render_text_to_image()
        else:
            self._o.font_set(font_name, font_size)

        new_size = self._o.geometry_get()[1]
        if old_size != new_size:
            #print "[TEXT REFLOW]: font change", old_size, new_size
            self._request_reflow("size", old_size, new_size)
Exemple #5
0
    def process(self):
        # TODO fix font locations to be configurable
        imlib2.add_font_path("/usr/share/fonts/truetype/")
        imlib2.add_font_path("/usr/share/fonts/truetype/freefont/")
        self.default_font = imlib2.load_font("FreeSans", 20)

        wf = self.artifact.previous_artifact_filepath
        image = imlib2.open(wf)
        new_image = self.do_im(image)

        # Most of the time, we can just modify the image in do_im, but in some
        # cases we need to return a new image object, i.e. when cropping. So,
        # if do_im returns anything replace the image with the returned image.
        if new_image:
            image = new_image

        image.save(self.artifact.filepath())
Exemple #6
0
 def _get_computed_font_size(self):
     font_name, font_size = self["font"]
     if self["size"][1] == "auto":
         if isinstance(font_size, str):
             font_size = self._compute_relative_value(font_size, 24)
         if self._o.type_get() != "image":
             return font_size
         # Imlib2 seems to want font size in points, so we need to
         # compensate. Set font size as target_height and calculate later.
         target_height = self['font'][1]
     
     elif self._o.type_get() != "image":
         # Requires support from kaa.evas for Imaging stuff.
         raise ValueError, "NYI"
     else:
         target_height = self._get_computed_size()[1]
     font = imlib2.load_font(font_name, target_height * 0.5)
     metrics = font.get_text_size(self["text"])
     diff = target_height * 0.5 / metrics[1]
     return target_height * diff
Exemple #7
0
    def process(self):
        font_paths = self.FONT_PATHS
        if self.artifact.args.has_key('font-path'):
            font_paths.extend(self.artifact.args['font-path'])

        for path in font_paths:
            imlib2.add_font_path(path)

        self.default_font = imlib2.load_font("FreeSans", 20)

        wf = self.artifact.previous_artifact_filepath
        image = imlib2.open(wf)
        new_image = self.do_im(image)

        # Most of the time, we can just modify the image in do_im, but in some
        # cases we need to return a new image object, i.e. when cropping. So,
        # if do_im returns anything replace the image with the returned image.
        if new_image:
            image = new_image

        image.save(self.artifact.filepath())
Exemple #8
0
def load_font(font, size):
    return imlib2.load_font(font, size)