[cairo-commit] cairomm/cairomm Makefile.am, 1.4, 1.5 scaledfont.cc,
NONE, 1.1 scaledfont.h, NONE, 1.1
Jonathon Jongsma
commit at pdx.freedesktop.org
Tue Jul 4 16:06:09 PDT 2006
Committed by: jjongsma
Update of /cvs/cairo/cairomm/cairomm
In directory kemper:/tmp/cvs-serv13672/cairomm
Modified Files:
Makefile.am
Added Files:
scaledfont.cc scaledfont.h
Log Message:
2006-07-04 Jonathon Jongsma <jonathon.jongsma at gmail.com>
* cairomm/scaledfont.cc, cairomm/scaledfont.h: wrap ScaledFont, including
new API for cairo 1.2
* cairomm/Makefile.am: add scaledfont.* to list of sources
Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/cairomm/cairomm/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Makefile.am 24 Jan 2006 11:48:42 -0000 1.4
+++ Makefile.am 4 Jul 2006 23:06:07 -0000 1.5
@@ -2,9 +2,9 @@
INCLUDES = -I$(top_srcdir) @CAIROMM_CFLAGS@
-h_sources_public = cairomm.h context.h enums.h fontface.h fontoptions.h path.h pattern.h surface.h xlib_surface.h win32_surface.h exception.h refptr.h
+h_sources_public = cairomm.h context.h enums.h fontface.h fontoptions.h path.h pattern.h surface.h xlib_surface.h win32_surface.h exception.h refptr.h scaledfont.h
h_sources_private = private.h
-cc_sources = context.cc fontface.cc fontoptions.cc path.cc pattern.cc surface.cc xlib_surface.cc win32_surface.cc exception.cc
+cc_sources = context.cc fontface.cc fontoptions.cc path.cc pattern.cc surface.cc xlib_surface.cc win32_surface.cc exception.cc scaledfont.cc
cc_sources_private = private.cc
# Support for DLL on cygwin/mingw using libtool > 1.4
--- NEW FILE: scaledfont.cc ---
/* Copyright (C) 2006 The cairomm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <cairomm/scaledfont.h>
#include <cairomm/private.h> // for check_status_and_throw_exception
namespace Cairo
{
ScaledFont::ScaledFont(cobject* cobj, bool has_reference)
{
if(has_reference)
m_cobject = cobj;
else
m_cobject = cairo_scaled_font_reference(cobj);
}
RefPtr<ScaledFont> ScaledFont::create(FontFace font_face, Matrix& font_matrix,
Matrix& ctm, FontOptions options)
{
cairo_scaled_font_t* cobj = cairo_scaled_font_create(font_face.cobj(),
static_cast<cairo_matrix_t*>(&font_matrix),
static_cast<cairo_matrix_t*>(&ctm), options.cobj()
);
check_status_and_throw_exception(cairo_scaled_font_status(cobj));
return RefPtr<ScaledFont>(new ScaledFont(cobj, false));
}
void ScaledFont::extents(FontExtents& extents) const
{
cairo_scaled_font_extents(m_cobject, static_cast<cairo_font_extents_t*>(&extents));
check_object_status_and_throw_exception(*this);
}
void ScaledFont::text_extents(const std::string& utf8, TextExtents& extents) const
{
cairo_scaled_font_text_extents(m_cobject, utf8.c_str(), static_cast<cairo_text_extents_t*>(&extents));
check_object_status_and_throw_exception(*this);
}
void ScaledFont::glyph_extents(std::vector<Glyph> glyphs, TextExtents& extents)
{
// copy the data from the vector to a standard C array. I don't believe
// this will be a frequently used function so I think the performance hit is
// more than offset by the increased flexibility of the STL interface.
Glyph glyph_array[glyphs.size()];
std::copy(glyphs.begin(), glyphs.end(), glyph_array);
cairo_scaled_font_glyph_extents(m_cobject, glyph_array, glyphs.size(),
static_cast<cairo_text_extents_t*>(&extents));
check_object_status_and_throw_exception(*this);
}
RefPtr<FontFace> ScaledFont::get_font_face() const
{
cairo_font_face_t* face = cairo_scaled_font_get_font_face(m_cobject);
check_object_status_and_throw_exception(*this);
return RefPtr<FontFace>(new FontFace(face, true));
}
void ScaledFont::get_font_options(FontOptions& options) const
{
cairo_scaled_font_get_font_options(m_cobject, options.cobj());
check_object_status_and_throw_exception(*this);
}
void ScaledFont::get_font_matrix(Matrix& font_matrix) const
{
cairo_scaled_font_get_font_matrix(m_cobject,
static_cast<cairo_matrix_t*>(&font_matrix));
check_object_status_and_throw_exception(*this);
}
void ScaledFont::get_ctm(Matrix& ctm) const
{
cairo_scaled_font_get_ctm(m_cobject, static_cast<cairo_matrix_t*>(&ctm));
check_object_status_and_throw_exception(*this);
}
FontType ScaledFont::get_type() const
{
cairo_font_type_t font_type = cairo_scaled_font_get_type(m_cobject);
check_object_status_and_throw_exception(*this);
return static_cast<FontType>(font_type);
}
} // namespace Cairo
// vim: ts=2 sw=2 et
--- NEW FILE: scaledfont.h ---
/* Copyright (C) 2006 The cairomm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifndef __CAIROMM_SCALEDFONT_H
#define __CAIROMM_SCALEDFONT_H
#include <cairomm/context.h> // Matrix
#include <cairomm/fontoptions.h> // Matrix
namespace Cairo
{
typedef enum
{
} ScaledFontType;
/** A ScaledFont is a font scaled to a particular size and device resolution. It
* is most useful for low-level font usage where a library or application wants
* to cache a reference to a scaled font to speed up the computation of metrics.
*/
class ScaledFont
{
public:
/** The underlying C cairo object type */
typedef cairo_scaled_font_t cobject;
/** Provides acces to the underlying C cairo object */
inline cobject* cobj() { return m_cobject; }
/** Provides acces to the underlying C cairo object */
inline const cobject* cobj() const { return m_cobject; }
#ifndef DOXYGEN_IGNORE_THIS
// For use only by the cairomm implementation.
inline ErrorStatus get_status() const
{ return cairo_scaled_font_status(const_cast<cairo_scaled_font_t*>(cobj())); }
// for RefPtr
void reference() const { cairo_scaled_font_reference(m_cobject); }
void unreference() const { cairo_scaled_font_destroy(m_cobject); }
#endif //DOXYGEN_IGNORE_THIS
/** Createa C++ wrapper object from the C instance. This C++ object should
* then be given to a RefPtr.
*/
explicit ScaledFont(cobject* cobj, bool has_reference = false);
/** Creates a ScaledFont object from a font face and matrices that describe
* the size of the font and the environment in which it will be used.
*
* \param font_matrix font space to user space transformation matrix for the
* font. In the simplest case of a N point font, this matrix is just a scale
* by N, but it can also be used to shear the font or stretch it unequally
* along the two axes. See Context::set_font_matrix().
* \param ctm user to device transformation matrix with which the font will be
* used.
* \param options: options to use when getting metrics for the font and
* rendering with it.
*/
static RefPtr<ScaledFont> create(FontFace font_face, Matrix& font_matrix,
Matrix& ctm, FontOptions options);
/** Gets the metrics for a ScaledFont */
void extents(FontExtents& extents) const;
/** Gets the extents for a string of text. The extents describe a user-space
* rectangle that encloses the "inked" portion of the text drawn at the origin
* (0,0) (as it would be drawn by Context::show_text() if the cairo graphics
* state were set to the same font_face, font_matrix, ctm, and font_options as
* the ScaledFont object). Additionally, the x_advance and y_advance values
* indicate the amount by which the current point would be advanced by
* Context::show_text().
*
* Note that whitespace characters do not directly contribute to the size of
* the rectangle (extents.width and extents.height). They do contribute
* indirectly by changing the position of non-whitespace characters. In
* particular, trailing whitespace characters are likely to not affect the
* size of the rectangle, though they will affect the x_advance and y_advance
* values.
*
* \param utf8 a string of text, encoded in UTF-8
* \param extents Returns the extents of the given string
*
* \since 1.2
*/
void text_extents(const std::string& utf8, TextExtents& extents) const;
/** Gets the extents for an array of glyphs. The extents describe a user-space
* rectangle that encloses the "inked" portion of the glyphs, (as they would
* be drawn by Context::show_glyphs() if the cairo graphics state were set to the
* same font_face, font_matrix, ctm, and font_options as the ScaledFont
* object). Additionally, the x_advance and y_advance values indicate the
* amount by which the current point would be advanced by Context::show_glyphs().
*
* Note that whitespace glyphs do not contribute to the size of the rectangle
* (extents.width and extents.height).
*
* \param glyphs A vector of glyphs to calculate the extents of
* \param extents Returns the extents for the array of glyphs
**/
void glyph_extents(std::vector<Glyph> glyphs, TextExtents& extents);
/** The FontFace with which this ScaledFont was created.
* \since 1.2
*/
RefPtr<FontFace> get_font_face() const;
/** Gets the FontOptions with which the ScaledFont was created.
* \since 1.2
*/
void get_font_options(FontOptions& options) const;
/** Gets the font matrix with which the ScaledFont was created.
* \since 1.2
*/
void get_font_matrix(Matrix& font_matrix) const;
/** Gets the CTM with which the ScaledFont was created.
* \since 1.2
*/
void get_ctm(Matrix& ctm) const;
/** Gets the type of scaled Font
* \since 1.2
*/
FontType get_type() const;
protected:
/** The underlying C cairo object that is wrapped by this ScaledFont */
cobject* m_cobject;
};
}
#endif // __CAIROMM_SCALEDFONT_H
// vim: ts=2 sw=2 et
More information about the cairo-commit
mailing list