[Alephmodular-devel] CFontSpec musing
Status: Pre-Alpha
Brought to you by:
brefin
From: Br'fin <br...@ma...> - 2003-09-01 05:50:37
|
Following is what I'm currently trying to setup for handling CFontSpecs ... a combination of font, size, and style. Oddly enough, all the details you think might be here aren't. Constructing a CFontSpec_Impl is left to the drawing context. As are most of the ways one would access things such as text width. And most of the interesting details are all stored in the platform specific implementation (Not yet devised) Usage might go something like CBuffer::Context context=buffer.get_drawing_context() CFontSpec my_font(context->get_font("Monaco", 24, CFontSpec::bold)); int height= context->get_font_height(my_font); int width= context->get_text_width("Hello world", my_font); context->draw_text("Hello world", CPoint(0, 0), my_font, CColor::white); I decided to have all access through the context as the font may be specific (and cached) for the current buffer. (An OpenGL font spec, for instance, would probably own the storage of the appropriate display lists for each character.) Also, the context may have need to finesse the resulting values of these functions. For instance, I'm thinking of a scaled buffer type. (The actual buffer is perhaps the whole screen, but only claims to be 640x480) Where the drawing context is the main agent performing the transformations. Deciding that it should use large point sizes and the like. And needing to do two way transformations. Scaling is 2x Request for 24 point font becomes a 48 point font Request for text width fetches the actual value, then divides by two Request to draw at 0, 10 is changed into drawing at 0, 20 etc, etc -Jeremy Parsons /////////////////////////////////////////////////////////////////////// // // $Id: CFontSpec.h,v 1.1.2.1 2003/03/26 05:33:30 brefin Exp $ /////////////////////////////////////////////////////////////////////// // /* * CFontSpec.h * AlephModular * * Created by Br'fin on Sun Aug 31 2003. * */ #ifndef _CFONTSPEC_H #define _CFONTSPEC_H #include "cstypes.h" #include <memory> class CFontSpec { public: class CFontSpec_Impl { public: typedef std::auto_ptr<CFontSpec_Impl> Ptr; protected: CFontSpec_Impl() {} CFontSpec_Impl(const CFontSpec_Impl& impl) {} private: // Prevent copying/assignment CFontSpec_Impl& operator=(const CFontSpec_Impl& impl) { return *this; } // Private interface, accessed by CFontSpec friend class CFontSpec; virtual int16 _get_height() = 0; virtual int16 _get_line_spacing() = 0; virtual Ptr _clone() = 0; friend class std::auto_ptr<CFontSpec_Impl>; virtual ~CFontSpec_Impl(); }; enum StyleFlag { normal = 0, bold = 1, italic = 2, underline = 4, outline = 8, shadow = 0x10, condense = 0x20, extend = 0x40 }; typedef unsigned short Style; private: CFontSpec_Impl::Ptr impl; // Only our factory class (whatever it is) may use this CFontSpec(CFontSpec_Impl::Ptr _impl) : impl(_impl) {} // We don't let the user use these routines directly // instead they need to access relevant functions on the drawing context. // Why? So the context can adjust these values by any scaling properties // that it might have. friend class CDContext; int16 get_height() { return impl->_get_height(); } int16 get_line_spoacing() { return impl->_get_line_spacing(); } public: CFontSpec(const CFontSpec& spec) : impl(spec.impl->_clone()) {} CFontSpec& operator=(const CFontSpec& spec); ~CFontSpec() {} }; inline CFontSpec& CFontSpec::operator=(const CFontSpec& spec) { if (this == &spec) return *this; // Gracefully handle self assignment CFontSpec_Impl::Ptr tmp= spec.impl->_clone(); impl= tmp; return *this; } #endif |