Font name can now be scripted

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@291 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-04-22 22:37:20 +00:00
parent b0c6669384
commit e4500ce490
12 changed files with 100 additions and 74 deletions
+41 -32
View File
@@ -11,36 +11,47 @@
// ----------------------------------------------------------------------------- : Font
Font::Font()
: font(*wxNORMAL_FONT)
, size(font.GetPointSize())
: name()
, size(1)
, underline(false)
, weight_i(wxFONTWEIGHT_NORMAL), style_i(wxFONTSTYLE_NORMAL)
, scale_down_to(100000)
, shadow_displacement(0,0)
, separator_color(128,128,128)
{}
bool Font::update(Context& ctx) {
return color .update(ctx)
bool changes
= name .update(ctx)
| italic_name .update(ctx)
| size .update(ctx)
| weight .update(ctx)
| style .update(ctx)
| underline .update(ctx)
| color .update(ctx)
| shadow_color.update(ctx);
weight_i = weight() == _("bold") ? wxBOLD : wxNORMAL;
style_i = style() == _("italic") ? wxITALIC : wxNORMAL;
return changes;
}
void Font::initDependencies(Context& ctx, const Dependency& dep) const {
name .initDependencies(ctx, dep);
italic_name .initDependencies(ctx, dep);
size .initDependencies(ctx, dep);
weight .initDependencies(ctx, dep);
style .initDependencies(ctx, dep);
underline .initDependencies(ctx, dep);
color .initDependencies(ctx, dep);
shadow_color.initDependencies(ctx, dep);
}
FontP Font::make(bool bold, bool italic, bool placeholder_color, bool code_color, Color* other_color) const {
FontP f(new Font(*this));
if (bold) f->font.SetWeight(wxBOLD);
if (italic) {
if (!italic_name.empty()) {
f->font.SetFaceName(italic_name);
} else {
f->font.SetWeight(wxBOLD);
}
}
if (bold) f->weight_i = wxFONTWEIGHT_BOLD;
if (italic) f->style_i = wxFONTSTYLE_ITALIC;
if (code_color) {
f->color = Color(128,0,0);
f->font.SetFamily(wxFONTFAMILY_TELETYPE);
f->font.SetFaceName(_("Courier New"));
f->type = TYPEWRITER;
}
if (placeholder_color) {
f->color = f->separator_color;
@@ -52,29 +63,27 @@ FontP Font::make(bool bold, bool italic, bool placeholder_color, bool code_color
return f;
}
void reflect_font(Reader& tag, Font& font) {
String name, weight, style;
double size = -1;
wxFont Font::toWxFont(double scale) const {
int size_i = scale * size;
if (name().empty()) {
wxFont font = *wxNORMAL_FONT;
font.SetPointSize(size > 1 ? size_i : scale * font.GetPointSize());
return font;
} else if (type == TYPEWRITER) {
return wxFont(size_i, wxFONTFAMILY_TELETYPE, weight_i, underline(), _("Courier New"));
} else if (style_i == wxFONTSTYLE_ITALIC && !italic_name().empty()) {
return wxFont(size_i, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, weight_i, underline(), italic_name());
} else {
return wxFont(size_i, wxFONTFAMILY_DEFAULT, style_i, weight_i, underline(), name());
}
}
IMPLEMENT_REFLECTION(Font) {
REFLECT(name);
REFLECT(size);
REFLECT(weight);
REFLECT(style);
if (!name.empty()) font.font.SetFaceName(name);
if (size > 0) font.font.SetPointSize((int) (font.size = size));
if (!weight.empty()) font.font.SetWeight(weight == _("bold") ? wxBOLD : wxNORMAL);
if (!style.empty()) font.font.SetWeight(style == _("italic") ? wxITALIC : wxNORMAL);
}
template <typename Tag>
void reflect_font(Tag& tag, const Font& font) {
REFLECT_N("name", font.font.GetFaceName());
REFLECT_N("size", font.size);
REFLECT_N("weight", font.font.GetWeight() == wxBOLD ? _("bold") : _("normal"));
REFLECT_N("style", font.font.GetStyle() == wxITALIC ? _("italic") : _("normal"));
}
IMPLEMENT_REFLECTION(Font) {
reflect_font(tag, *this);
REFLECT(underline);
REFLECT(italic_name);
REFLECT(color);
REFLECT(scale_down_to);
+18 -8
View File
@@ -21,14 +21,21 @@ DECLARE_POINTER_TYPE(Font);
/** Contains additional information about scaling, color and shadow */
class Font {
public:
wxFont font; ///< The actual wxFont to use
double size; ///< Size of the font
double scale_down_to; ///< Smallest size to scale down to
Scriptable<Color> color; ///< Color to use
Scriptable<Color> shadow_color; ///< Color for shadow
RealSize shadow_displacement; ///< Position of the shadow
String italic_name; ///< Font name for italic text (optional)
Color separator_color; ///< Color for <sep> text
Scriptable<String> name; ///< Name of the font
Scriptable<String> italic_name; ///< Font name for italic text (optional)
Scriptable<double> size; ///< Size of the font
Scriptable<String> weight, style; ///< Weight and style of the font (bold/italic)
Scriptable<bool> underline; ///< Underlined?
int weight_i, style_i; ///< wx constants for weight and style
double scale_down_to; ///< Smallest size to scale down to
Scriptable<Color> color; ///< Color to use
Scriptable<Color> shadow_color; ///< Color for shadow
RealSize shadow_displacement; ///< Position of the shadow
Color separator_color; ///< Color for <sep> text
enum {
NORMAL,
TYPEWRITER, ///< Use a typewriter font
} type;
Font();
@@ -43,6 +50,9 @@ class Font {
/// Make a bold/italic/placeholder version of this font
FontP make(bool bold, bool italic, bool placeholder_color, bool code_color, Color* other_color) const;
/// Convert this font to a wxFont
wxFont toWxFont(double scale) const;
private:
DECLARE_REFLECTION();
};
+1 -1
View File
@@ -676,7 +676,7 @@ void ApprenticeExportWindow::onOk(wxCommandEvent& ev) {
if (set->apprentice_code != new_set_code) {
// changed something in the set
set->apprentice_code = new_set_code;
//%%set->actions.atSavePoint = false; // tell the user he needs to save
//set->actions.atSavePoint = false; // TODO: tell the user he needs to save
}
// Check if apprentice exists
if (!wxFileExists(settings.apprentice_location + _("\\appr.exe"))) {
+12 -9
View File
@@ -151,6 +151,15 @@ RealSize SymbolInFont::size(Context& ctx, Package& pkg, double size) {
void SymbolInFont::update(Context& ctx) {
enabled.update(ctx);
}
void SymbolFont::update(Context& ctx) const {
// update all symbol-in-fonts
FOR_EACH_CONST(sym, symbols) {
sym->update(ctx);
}
if (text_font) {
text_font->update(ctx);
}
}
IMPLEMENT_REFLECTION(SymbolInFont) {
REFLECT(code);
@@ -172,10 +181,7 @@ class SymbolFont::DrawableSymbol {
};
void SymbolFont::split(const String& text, Context& ctx, SplitSymbols& out) const {
// update all symbol-in-fonts
FOR_EACH_CONST(sym, symbols) {
sym->update(ctx);
}
update(ctx);
// read a single symbol until we are done with the text
for (size_t pos = 0 ; pos < text.size() ; ) {
// 1. check merged numbers
@@ -264,7 +270,7 @@ void SymbolFont::drawWithText(RotatedDC& dc, Context& ctx, const RealRect& rect,
RealSize ts;
while (true) {
if (size <= 0) return; // text too small
dc.SetFont(text_font->font, size);
dc.SetFont(*text_font, size / text_font->size);
ts = dc.GetTextExtent(text);
if (ts.width <= sym_rect.width && ts.height <= sym_rect.height) {
break; // text fits
@@ -326,10 +332,7 @@ RealSize SymbolFont::defaultSymbolSize(Context& ctx, double font_size) {
wxMenu* SymbolFont::insertSymbolMenu(Context& ctx) {
if (!processed_insert_symbol_menu && insert_symbol_menu) {
// update all symbol-in-fonts
FOR_EACH_CONST(sym, symbols) {
sym->update(ctx);
}
update(ctx);
// Make menu
processed_insert_symbol_menu = insert_symbol_menu->makeMenu(ID_INSERT_SYMBOL_MENU_MIN, ctx, *this);
}
+4 -1
View File
@@ -59,7 +59,7 @@ class SymbolFont : public Packaged {
/// Process a choice from the insert symbol menu
/** Return the code representing the symbol */
String insertSymbolCode(int menu_id) const;
private:
UInt img_size; ///< Font size that the images use
UInt min_size; ///< Minimum font size
@@ -80,6 +80,9 @@ class SymbolFont : public Packaged {
friend class InsertSymbolMenu;
vector<SymbolInFontP> symbols; ///< The individual symbols
// Script update
void update(Context& ctx) const;
/// Find the default symbol
/** may return nullptr */
SymbolInFont* defaultSymbol() const;