Blame cairomm/win32_font.h

Packit 908522
/* Copyright (C) 2008 Jonathon Jongsma
Packit 908522
 *
Packit 908522
 * This library is free software; you can redistribute it and/or
Packit 908522
 * modify it under the terms of the GNU Library General Public
Packit 908522
 * License as published by the Free Software Foundation; either
Packit 908522
 * version 2 of the License, or (at your option) any later version.
Packit 908522
 *
Packit 908522
 * This library is distributed in the hope that it will be useful,
Packit 908522
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 908522
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 908522
 * Library General Public License for more details.
Packit 908522
 *
Packit 908522
 * You should have received a copy of the GNU Library General Public
Packit 908522
 * License along with this library; if not, write to the Free Software
Packit 908522
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 908522
 * 02110-1301, USA.
Packit 908522
 */
Packit 908522
#ifndef __CAIROMM_WIN32_FONT_H
Packit 908522
#define __CAIROMM_WIN32_FONT_H
Packit 908522
Packit 908522
#include <cairo-features.h>
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_WIN32_FONT
Packit 908522
#include <cairo-win32.h>
Packit 908522
#include <cairomm/fontface.h>
Packit 908522
#include <cairomm/scaledfont.h>
Packit 908522
Packit 908522
namespace Cairo
Packit 908522
{
Packit 908522
Packit 908522
/** Font support for Microsoft Windows.
Packit 908522
 *
Packit 908522
 * @since 1.8
Packit 908522
 */
Packit 908522
class Win32FontFace : public FontFace
Packit 908522
{
Packit 908522
public:
Packit 908522
Packit 908522
  /** Creates a new font for the Win32 font backend based on a LOGFONT. This
Packit 908522
   * font can then be used with Context::set_font_face() or
Packit 908522
   * Win32ScaledFont::create().
Packit 908522
   *
Packit 908522
   * @param logfont A LOGFONTW structure specifying the font to use. The
Packit 908522
   * lfHeight, lfWidth, lfOrientation and lfEscapement fields of this structure
Packit 908522
   * are ignored.
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  static RefPtr<Win32FontFace> create(LOGFONTW* logfont);
Packit 908522
Packit 908522
  /** Creates a new font for the Win32 font backend based on a HFONT. This font
Packit 908522
   * can then be used with Context::set_font_face() or Win32ScaledFont::create().
Packit 908522
   *
Packit 908522
   * @param font An HFONT structure specifying the font to use.
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  static RefPtr<Win32FontFace> create(HFONT font);
Packit 908522
Packit 908522
  /** Creates a new font for the Win32 font backend based on a LOGFONT. This
Packit 908522
   * font can then be used with Context::set_font_face() or
Packit 908522
   * Win32ScaledFont::create().
Packit 908522
   *
Packit 908522
   * @param logfont A LOGFONTW structure specifying the font to use. If hfont is
Packit 908522
   * null then the lfHeight, lfWidth, lfOrientation and lfEscapement fields of
Packit 908522
   * this structure are ignored. Otherwise lfWidth, lfOrientation and
Packit 908522
   * lfEscapement must be zero.
Packit 908522
   * @param font An HFONT that can be used when the font matrix is a scale by
Packit 908522
   * -lfHeight and the CTM is identity. 
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  static RefPtr<Win32FontFace> create(LOGFONTW* logfont, HFONT font);
Packit 908522
Packit 908522
protected:
Packit 908522
  Win32FontFace(LOGFONTW* logfont);
Packit 908522
  Win32FontFace(HFONT font);
Packit 908522
  Win32FontFace(LOGFONTW* logfont, HFONT font);
Packit 908522
};
Packit 908522
Packit 908522
Packit 908522
/** Scaled Font implementation for Microsoft Windows fonts.
Packit 908522
 *
Packit 908522
 * @since 1.8
Packit 908522
 */
Packit 908522
class Win32ScaledFont : public ScaledFont
Packit 908522
{
Packit 908522
public:
Packit 908522
Packit 908522
  /** Creates a scaled font for the given Win32FontFace.
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  static RefPtr<Win32ScaledFont> create(const RefPtr<Win32FontFace>& font_face,
Packit 908522
                                        const Matrix& font_matrix,
Packit 908522
                                        const Matrix& ctm,
Packit 908522
                                        const FontOptions& options = FontOptions());
Packit 908522
Packit 908522
  /** Selects the font into the given device context and changes the map mode
Packit 908522
   * and world transformation of the device context to match that of the font.
Packit 908522
   * This function is intended for use when using layout APIs such as Uniscribe
Packit 908522
   * to do text layout with the cairo font. After finishing using the device
Packit 908522
   * context, you must call done_font() to release any resources allocated by
Packit 908522
   * this function.
Packit 908522
   *
Packit 908522
   * See get_metrics_factor() for converting logical coordinates from the device
Packit 908522
   * context to font space.
Packit 908522
   *
Packit 908522
   * Normally, calls to SaveDC() and RestoreDC() would be made around the use of
Packit 908522
   * this function to preserve the original graphics state.
Packit 908522
   *
Packit 908522
   * @param scaled_font A cairo_scaled_font_t from the Win32 font backend. Such
Packit 908522
   * an object can be created with Win32FontFace::create_for_logfontw().
Packit 908522
   * @param hdc a device context
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  void select_font(HDC hdc);
Packit 908522
Packit 908522
  /** Releases any resources allocated by select_font()
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  void done_font();
Packit 908522
Packit 908522
  /** Gets a scale factor between logical coordinates in the coordinate space
Packit 908522
   * used by select_font() (that is, the coordinate system used by the Windows
Packit 908522
   * functions to return metrics) and font space coordinates.
Packit 908522
   *
Packit 908522
   * @return factor to multiply logical units by to get font space coordinates.
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  double get_metrics_factor() const;
Packit 908522
Packit 908522
  /** Gets the transformation mapping the logical space used by this scaled font
Packit 908522
   * to device space.
Packit 908522
   *
Packit 908522
   * @param logical_to_device matrix to return
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  void get_logical_to_device(Matrix& logical_to_device) const;
Packit 908522
Packit 908522
  /** Gets the transformation mapping device space to the logical space used by
Packit 908522
   * this scaled font.
Packit 908522
   *
Packit 908522
   * @param device_to_logical matrix to return
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  void get_device_to_logical(Matrix& device_to_logical) const;
Packit 908522
Packit 908522
protected:
Packit 908522
  Win32ScaledFont(const RefPtr<Win32FontFace>& font_face,
Packit 908522
                  const Matrix& font_matrix,
Packit 908522
                  const Matrix& ctm,
Packit 908522
                  const FontOptions& options = FontOptions());
Packit 908522
};
Packit 908522
Packit 908522
}
Packit 908522
Packit 908522
#endif // CAIRO_HAS_WIN32_FONT
Packit 908522
Packit 908522
#endif // __CAIROMM_WIN32_FONT_H