3 * Psychlops Standard Library (Universal)
5 * Last Modified 2005/09/25 by Kenchi HOSOKAWA
6 * (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
9 #ifndef HEADER_PSYCHLOPS_GRAPHIC_FONT
10 #define HEADER_PSYCHLOPS_GRAPHIC_FONT
12 #include "psychlops_g_fundamental.h"
13 #include "psychlops_g_module.h"
14 #include "psychlops_g_shape.h"
15 #include "../ApplicationInterfaces/psychlops_code_snippets.h"
25 class APICanvasProperties;
26 class APIImageProperties;
27 class APIFontProperties;
33 double x_height, cap_height, descender_height, ascender_height;
36 virtual double getWidthOf(char * str);
37 virtual double getWidthOf(std::string str) = 0;
45 static bool initialized;
46 static const size_t ASCII_NUM = 128;
47 static const size_t font_minimum_proportion[ASCII_NUM];
48 static Image *font_minimum;
49 static void initializeFontMinimum();
52 static Font default_font;
54 enum Style { normal_style, italic, oblique };
55 enum Weight { normal_weight=400, bold=700 };
59 std::vector<std::wstring> family;
62 Font(double size_, int weight_=400, Style style_ = normal_style, std::wstring family_=L"default");
63 Font(std::wstring family_, double size_, int weight_=400, Style style_ = normal_style);
64 Font(const wchar_t* family_, double size_, int weight_=400, Style style_ = normal_style);
66 Font& set(double size_, int weight_=400, Style style_ = normal_style, std::wstring family_=L"");
\r
67 Font& set(std::wstring family_, double size_, int weight_=400, Style style_ = normal_style);
\r
68 Font& set(const wchar_t* family_, double size_, int weight_=400, Style style_ = normal_style);
72 class Letters : virtual public Shape, virtual public FigureDatum {
74 friend class APICanvasProperties;
75 friend class APIImageProperties;
76 friend class APIFontProperties;
80 APIFontProperties* id;
83 Cache(APIFontProperties* id__, bool dirty__);
85 typedef std::map<DrawableWithCache*, Cache> CacheID;
86 mutable CacheID caches;
88 double width_, height_;
93 enum HorizontalAlign { NOT_SPECIFIED=-1, TEXT_ALIGN_LEFT=0, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT };
94 HorizontalAlign align;
95 enum VerticalAlign { BASELINE, TEXT_ALIGN_TOP, TEXT_ALIGN_MIDDLE, TEXT_ALIGN_BOTTOM, TEXT_ALIGN_TEXT_TOP, TEXT_ALIGN_TEXT_BOTTOM };
\r
96 VerticalAlign vertical_align;
\r
97 //enum AlignmentBaseline { AUTO=0, BASELINE, BEFORE_EDGE, TEXT_BEFORE_EDGE, MIDDLE, CENTRAL, AFTER_EDGE, TEXT_AFTER_EDGE, IDEOGRAPHIC, ALPHABETIC, HANGING, MATHEMATICAL, INHERIT };
\r
98 //AlignmentBaseline alignment_baseline;
\r
101 Letters(const char *init_str, int size_, const Font& init_font = Font::default_font);
102 Letters(const char *init_str, const Font& init_font = Font::default_font);
103 Letters(const std::wstring &init_str, const Font& init_font = Font::default_font);
105 virtual Font& getFont();
106 virtual std::wstring& getString();
107 virtual Letters& setFont(const Font &init_font);
108 virtual Letters& setString(const char *init_str);
109 virtual Letters& setString(const char *init_str, int size_);
110 virtual Letters& setString(const std::wstring &init_str);
\r
111 virtual Letters& string(const char *init_str);
\r
112 virtual Letters& string(const char *init_str, int size_);
\r
113 virtual Letters& string(const std::wstring &init_str);
114 virtual Letters& cache(DrawableWithCache &target = *DrawableWithCache::prime);
115 virtual Letters& uncache(DrawableWithCache &target = *DrawableWithCache::prime);
116 virtual Letters& operator =(const std::wstring &init_str);
117 using Shape::centering;
118 virtual Letters& centering(const Point& p);
119 virtual Letters& centering(const Point& p, bool realign_flag);
120 virtual Letters& locate(const Point& p);
121 virtual Letters& locate(double x, double y, double z=0.0);
\r
123 virtual Letters& centering(const Figure& fig);
124 virtual Letters& centering(const Drawable &target = *Drawable::prime);
125 virtual Letters& centering(const double x, const double y, const double z = 0);
126 virtual Letters& shift(const double x, const double y, const double z = 0);
\r
128 virtual Letters& draw(Drawable &target = *Drawable::prime);
129 virtual Letters& draw(const Color &col, Drawable &target = *Drawable::prime);
130 virtual Letters& draw(const Stroke &strk, Drawable &target = *Drawable::prime);
131 virtual Letters& draw(const Color &col, HorizontalAlign horiz_align, Drawable &target = *Drawable::prime);
134 } /* <- namespace Psycholops */