OSDN Git Service

first
[psychlops/cpp.git] / psychlops / core / graphic / psychlops_g_font.h
1 /*
2  *  psychlops_g_font.h
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2005/09/25 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 #ifndef HEADER_PSYCHLOPS_GRAPHIC_FONT
10 #define HEADER_PSYCHLOPS_GRAPHIC_FONT
11
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"
16 #include <string>
17 #include <map>
18
19 namespace Psychlops {
20
21         class Font;
22         class Letters;
23         class Canvas;
24         class Display;
25         class APICanvasProperties;
26         class APIImageProperties;
27         class APIFontProperties;
28 /*
29         class Font {
30                 friend class Letters;
31
32                 public:
33                 double x_height, cap_height, descender_height, ascender_height;
34
35                 virtual ~Font();
36                 virtual double getWidthOf(char * str);
37                 virtual double getWidthOf(std::string str) = 0;
38         };
39 */
40
41
42         class Font {
43                 friend class Canvas;
44                 private:
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();
50
51                 public:
52                 static Font default_font;
53
54                 enum Style { normal_style, italic, oblique };
55                 enum Weight { normal_weight=400, bold=700 };
56                 double size;
57                 int weight;
58                 Style style;
59                 std::vector<std::wstring> family;
60
61                 Font();
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);
65                 virtual ~Font();\r
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);
69         };
70
71
72         class Letters : virtual public Shape, virtual public FigureDatum {
73                 friend class Canvas;
74                 friend class APICanvasProperties;
75                 friend class APIImageProperties;
76                 friend class APIFontProperties;
77
78                 protected:
79                 struct Cache {
80                         APIFontProperties* id;
81                         bool dirty;
82                         Cache();
83                         Cache(APIFontProperties* id__, bool dirty__);
84                 };
85                 typedef std::map<DrawableWithCache*, Cache> CacheID;
86                 mutable CacheID caches;
87 //              bool cached;
88                 double width_, height_;
89
90                 public:\r
91                 Font font;\r
92                 std::wstring str;
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
99
100                 Letters();
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);
104                 virtual ~Letters();
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
122
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
127
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);
132         };
133
134 }       /*      <- namespace Psycholops         */
135
136
137 #endif