[cairo] cairo_select_font() (was:
cairo_scale_font/cairo_transform_font())
Ned Konz
ned at squeakland.org
Sat Mar 19 13:57:23 PST 2005
On Saturday 19 March 2005 10:45 am, Øyvind Kolås wrote:
> Ok, this would make it possible to act upon the current font object
> from a binding. I'd also like to split out the components of the
> "FontName", making a coding style like:
>
> cr.font.name = "Sans"
> cr.font.slant = Cairo::FONT_SLANT_ITALIC
> cr.font.size = 12
>
> possible in for instance the ruby binding.
I don't think so, since what Owen is calling the font_name_t has not
necessarily got the (human-centric) name of the font in it.
Instead, this is a structure defined by a given backend.
cairo_scaled_font_t (*create_scaled_font) (void *name, cairo_matrix_t
*font_matrix, cairo_matrix_t *ctm);
And the "name" is not necessarily what most of us think of as a font name (it
would probably be a filename in the case of the FT2 backend). It's just some
identifier that can be used to find the description of an unscaled font.
Since different backends would define "name" differently, you wouldn't have a
single way of getting (say) a font family name from an abstract font_name_t.
Instead what you'd want to do for a language binding is to keep track of the
constructor arguments, and/or know how to query the different back-end
specific font_name_t objects:
class CairoFontName < Object
end
class CairoFtFontName < CairoFontName
def initialize(ftFace, loadFlags)
@face = ftFace
@flags = loadFlags
end
def self.newFromFile(filename, loadFlags=0)
face = FT2Face.new(filename)
self.new(face, loadFlags)
end
def self.newFromFcPattern(fcPattern)
face, flags = findFtFace(fcPattern)
self new(face, flags)
end
def familyName
@face.familyName
end
end
class CairoSimpleFontName < CairoFontName
def initialize(familyName, slant=SlantRoman, weight=WeightRegular)
@familyName = familyName
@slant = slant
@weight = weight
end
def familyName
@familyName
end
end
class CairoContext
# takes a CairoFontName
def setFontName(fname)
...
end
end
--
Ned Konz
http://bike-nomad.com/squeak/
More information about the cairo
mailing list