Symbol font measurments (margin/fontsize) now scaled by font size, this requires all symbol files to change (or you get really large margins);

Symbol fonts now support stretching/compressing of text;
Made the default symbols of mana-future lighter (compare with real cards);
Use sort_text instead of sort for vanguard;
Fixed initial card list for vs

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@643 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-08-29 14:35:39 +00:00
parent 1ca1f8d4be
commit 5fa4867cdc
24 changed files with 112 additions and 62 deletions
+3 -1
View File
@@ -15,6 +15,7 @@ Font::Font()
, size(1)
, underline(false)
, scale_down_to(100000)
, max_stretch(1.0)
, shadow_displacement(0,0)
, separator_color(128,128,128)
, flags(FONT_NORMAL)
@@ -70,7 +71,7 @@ FontP Font::make(int add_flags, Color* other_color) const {
}
wxFont Font::toWxFont(double scale) const {
int size_i = scale * size;
int size_i = to_int(scale * size);
int weight_i = flags & FONT_BOLD ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL;
int style_i = flags & FONT_ITALIC ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL;
// make font
@@ -108,6 +109,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Font) {
REFLECT(italic_name);
REFLECT(color);
REFLECT(scale_down_to);
REFLECT(max_stretch);
REFLECT_N("shadow_displacement_x", shadow_displacement.width);
REFLECT_N("shadow_displacement_y", shadow_displacement.height);
REFLECT(shadow_color);
+1
View File
@@ -39,6 +39,7 @@ class Font : public IntrusivePtrBase<Font> {
Scriptable<String> weight, style; ///< Weight and style of the font (bold/italic)
Scriptable<bool> underline; ///< Underlined?
double scale_down_to; ///< Smallest size to scale down to
double max_stretch; ///< How much should the font be stretched before scaling down?
Scriptable<Color> color; ///< Color to use
Scriptable<Color> shadow_color; ///< Color for shadow
RealSize shadow_displacement; ///< Position of the shadow
+36 -24
View File
@@ -268,33 +268,39 @@ void SymbolFont::drawWithText(RotatedDC& dc, const RealRect& rect, double font_s
// 2. draw text
if (!text_font) return;
// subtract margins from size
sym_rect.x += text_margin_left;
sym_rect.y += text_margin_top;
sym_rect.width -= text_margin_left + text_margin_right;
sym_rect.height -= text_margin_top + text_margin_bottom;
sym_rect.x += font_size * text_margin_left;
sym_rect.y += font_size * text_margin_top;
sym_rect.width -= font_size * (text_margin_left + text_margin_right);
sym_rect.height -= font_size * (text_margin_top + text_margin_bottom);
// setup text, shrink it
double size = text_font->size; // TODO : incorporate shrink factor?
double size = font_size * text_font->size;
double stretch = 1.0;
RealSize ts;
while (true) {
if (size <= 0) return; // text too small
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
} else {
// text doesn't fit
size -= dc.getFontSizeStep();
if (ts.height <= sym_rect.height) {
if (ts.width <= sym_rect.width) {
break; // text fits
} else if (ts.width * text_font->max_stretch <= sym_rect.width) {
stretch = sym_rect.width / ts.width;
ts.width = sym_rect.width; // for alignment
break;
}
}
// text doesn't fit
size -= dc.getFontSizeStep();
}
// align text
RealPoint text_pos = align_in_rect(text_alignment, ts, sym_rect);
// draw text
if (text_font->hasShadow()) {
dc.SetTextForeground(text_font->shadow_color);
dc.DrawText(text, text_pos + text_font->shadow_displacement);
dc.DrawText(text, text_pos + text_font->shadow_displacement * font_size, 0, 1, stretch);
}
dc.SetTextForeground(text_font->color);
dc.DrawText(text, text_pos);
dc.DrawText(text, text_pos, 0, 1, stretch);
}
Image SymbolFont::getImage(double font_size, const DrawableSymbol& sym) {
@@ -312,33 +318,39 @@ Image SymbolFont::getImage(double font_size, const DrawableSymbol& sym) {
RealRect sym_rect(0,0,bmp.GetWidth(),bmp.GetHeight());
RotatedDC rdc(dc, 0, sym_rect, 1, QUALITY_AA);
// subtract margins from size
sym_rect.x += text_margin_left;
sym_rect.y += text_margin_top;
sym_rect.width -= text_margin_left + text_margin_right;
sym_rect.height -= text_margin_top + text_margin_bottom;
sym_rect.x += font_size * text_margin_left;
sym_rect.y += font_size * text_margin_top;
sym_rect.width -= font_size * (text_margin_left + text_margin_right);
sym_rect.height -= font_size * (text_margin_top + text_margin_bottom);
// setup text, shrink it
double size = text_font->size; // TODO : incorporate shrink factor?
double size = font_size * text_font->size;
double stretch = 1.0;
RealSize ts;
while (true) {
if (size <= 0) return def->getImage(*this, font_size); // text too small
rdc.SetFont(*text_font, size / text_font->size);
ts = rdc.GetTextExtent(sym.text);
if (ts.width <= sym_rect.width && ts.height <= sym_rect.height) {
break; // text fits
} else {
// text doesn't fit
size -= rdc.getFontSizeStep();
if (ts.height <= sym_rect.height) {
if (ts.width <= sym_rect.width) {
break; // text fits
} else if (ts.width * text_font->max_stretch <= sym_rect.width) {
stretch = sym_rect.width / ts.width;
ts.width = sym_rect.width; // for alignment
break;
}
}
// text doesn't fit
size -= rdc.getFontSizeStep();
}
// align text
RealPoint text_pos = align_in_rect(text_alignment, ts, sym_rect);
// draw text
if (text_font->hasShadow()) {
rdc.SetTextForeground(text_font->shadow_color);
rdc.DrawText(sym.text, text_pos + text_font->shadow_displacement);
rdc.DrawText(sym.text, text_pos + text_font->shadow_displacement * font_size, 0, 1, stretch);
}
rdc.SetTextForeground(text_font->color);
rdc.DrawText(sym.text, text_pos);
rdc.DrawText(sym.text, text_pos, 0, 1, stretch);
// done
dc.SelectObject(wxNullBitmap);
return bmp.ConvertToImage();
+5 -2
View File
@@ -43,6 +43,8 @@ void downsample_to_alpha(Image& img_in, Image& img_out) {
int w1 = img_in.GetWidth(), w2 = img_out.GetWidth(), h = img_in.GetHeight();
int out_fact = (w2 << shift) / w1; // how much to output for 256 input = 1 pixel
int out_rest = (w2 << shift) % w1;
// make the image 'bolder' to compensate for compressing it
int mul = 128 + min(256, 128*w1/(text_scaling*w2));
for (int y = 0 ; y < h ; ++y) {
int in_rem = out_fact + out_rest;
for (int x = 0 ; x < w2 ; ++x) {
@@ -61,7 +63,7 @@ void downsample_to_alpha(Image& img_in, Image& img_out) {
in_rem -= out_rem;
}
// store
*out = tot >> shift;
*out = top(((tot >> shift) * mul) >> 8);
out += 1;
}
}
@@ -89,6 +91,7 @@ void downsample_to_alpha(Image& img_in, Image& img_out) {
int h1 = img_in.GetHeight(), w = img_out.GetWidth();
int out_fact = (h << shift) / h1; // how much to output for 256 input = 1 pixel
int out_rest = (h << shift) % h1;
int mul = 128 + min(256, 128*h1/(text_scaling*h));
for (int x = 0 ; x < w ; ++x) {
int in_rem = out_fact + out_rest;
for (int y = 0 ; y < h ; ++y) {
@@ -107,7 +110,7 @@ void downsample_to_alpha(Image& img_in, Image& img_out) {
in_rem -= out_rem;
}
// store
*out = tot >> shift;
*out = top(((tot >> shift) * mul) >> 8);
out += line_size;
}
in = in - h1 * line_size + 1;
+2 -2
View File
@@ -131,12 +131,12 @@ RotatedDC::RotatedDC(DC& dc, const Rotation& rotation, RenderQuality quality)
// ----------------------------------------------------------------------------- : RotatedDC : Drawing
void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_radius, int boldness) {
void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_radius, int boldness, double stretch_) {
if (text.empty()) return;
if (quality == QUALITY_AA) {
RealRect r(pos, GetTextExtent(text));
RealRect r_ext = trNoNeg(r);
draw_resampled_text(dc, r_ext, stretch(), revX(), revY(), angle, text, blur_radius, boldness);
draw_resampled_text(dc, r_ext, stretch_ * stretch(), revX(), revY(), angle, text, blur_radius, boldness);
} else if (quality == QUALITY_SUB_PIXEL) {
RealPoint p_ext = tr(pos)*text_scaling;
double usx,usy;
+1 -1
View File
@@ -151,7 +151,7 @@ class RotatedDC : public Rotation {
// --------------------------------------------------- : Drawing
void DrawText (const String& text, const RealPoint& pos, int blur_radius = 0, int boldness = 1);
void DrawText (const String& text, const RealPoint& pos, int blur_radius = 0, int boldness = 1, double stretch = 1.0);
/// Draw abitmap, it must already be zoomed!
void DrawBitmap(const Bitmap& bitmap, const RealPoint& pos);
/// Draw an image using the given combining mode, the image must already be zoomed!