Basic text rendering working;

Added Font (done) and SymbolFont (skeleton);
Added styling to set;
Added CountourMap;
Some script fixes

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@73 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-11-17 17:57:04 +00:00
parent ea5be88bdb
commit ce6a83e34b
45 changed files with 1595 additions and 84 deletions
+4 -2
View File
@@ -17,6 +17,7 @@
/** - K must have a unique member ->index of type UInt
* - There must exist a function void init_object(Key, Value&)
* that stores a new V object for a given key in the reference
* if the value is already set the function should do nothing
* - There must exist a function Key get_key(Value)
* that returns a key for a given value
* - For reflection there must exist a function String get_key_name(Value)
@@ -39,9 +40,10 @@ class IndexMap : private vector<Value> {
using vector<Value>::begin;
using vector<Value>::end;
/// Initialize this map with default values given a list of keys, has no effect if !empty()
/// Initialize this map with default values given a list of keys
/** has no effect if already initialized with the given keys */
void init(const vector<Key>& keys) {
if (!this->empty()) return;
if (this->size() == keys.size()) return;
this->reserve(keys.size());
for(vector<Key>::const_iterator it = keys.begin() ; it != keys.end() ; ++it) {
const Key& key = *it;
+1
View File
@@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------- : GetDefaultMember
template <> void GetDefaultMember::handle(const Char* const& v) { value = toScript(v); }
template <> void GetDefaultMember::handle(const String& v) { value = toScript(v); }
template <> void GetDefaultMember::handle(const int& v) { value = toScript(v); }
template <> void GetDefaultMember::handle(const unsigned int& v) { value = toScript((int)v); }
+4 -4
View File
@@ -192,13 +192,13 @@ void Reader::handle(map<String, V>& m) {
template <typename K, typename V>
void Reader::handle(IndexMap<K,V>& m) {
do {
UInt l = line_number;
//do {
// UInt l = line_number;
for (typename IndexMap<K,V>::iterator it = m.begin() ; it != m.end() ; ++it) {
handle(get_key_name(*it).c_str(), *it);
}
if (l == line_number) unknownKey(m);
} while (indent >= expected_indent);
// if (l == line_number) unknownKey(m);
//} while (indent >= expected_indent);
}
// ----------------------------------------------------------------------------- : Reflection
+25 -5
View File
@@ -41,7 +41,7 @@ class RealSize {
{}
/// Addition of two sizes
inline void operator += (const RealSize& s2) {
/* inline void operator += (const RealSize& s2) {
width += s2.width;
height += s2.height;
}
@@ -62,7 +62,7 @@ class RealSize {
inline RealSize operator - () const {
return RealSize(-width, -height);
}
*/
/// Multiplying a size by a scalar r, multiplies both components
inline void operator *= (double r) {
width *= r;
@@ -83,6 +83,26 @@ class RealSize {
}
};
/// Add two sizes horizontally
/** #### $$$ ####$$$
* #### + $$$ = ####$$$
* #### ####...
*/
inline RealSize addHorizontal(const RealSize& a, const RealSize& b) {
return RealSize(a.width + b.width, max(a.height, b.height));
}
/// Add two sizes vertically
/** #### $$$ ####
* #### + $$$ = ####
* #### ####
* $$$.
* $$$.
*/
inline RealSize addVertical(const RealSize& a, const RealSize& b) {
return RealSize(max(a.width, b.width), a.height + b.height);
}
// ----------------------------------------------------------------------------- : Rectangle using doubles
/// A rectangle (postion and size) using real (double) coordinats
@@ -110,9 +130,9 @@ class RealRect {
inline RealRect grow(double amount) {
return RealRect(position.x - amount, position.y - amount, size.width + 2 * amount, size.height + 2 * amount);
}
inline RealRect operator + (const RealRect& r) const {
return RealRect(position + r.position, size + r.size);
/// Move the coordinates by some amount
inline RealRect move(double dx, double dy, double dw, double dh) {
return RealRect(position.x + dx, position.y + dy, size.width + dw, size.height + dh);
}
};
+27 -2
View File
@@ -11,15 +11,25 @@
// ----------------------------------------------------------------------------- : Rotation
// constrain an angle to {0,90,180,270}
int constrain_angle(int angle) {
int a = ((angle + 45) % 360 + 360) % 360; // [0..360)
return (a / 90) * 90; // multiple of 90
}
Rotation::Rotation(int angle, const RealRect& rect, double zoom)
: angle(angle)
: angle(constrain_angle(angle))
, size(rect.size)
, origin(rect.position)
, zoom(zoom)
{
// set origin
if (revX()) origin.x += size.width;
if (revY()) origin.x += size.height;
if (revY()) origin.y += size.height;
}
RealRect Rotation::getExternalRect() const {
return RealRect(origin - RealSize(revX() ? size.width : 0, revY() ? size.height : 0), size);
}
RealPoint Rotation::tr(const RealPoint& p) const {
@@ -72,6 +82,21 @@ RealPoint Rotation::trInv(const RealPoint& p) const {
// ----------------------------------------------------------------------------- : Rotater
Rotater::Rotater(Rotation& rot, const Rotation& by)
: old(rot)
, rot(rot)
{
// apply rotation
RealRect new_ext = rot.trNoNeg(by.getExternalRect());
rot.angle = constrain_angle(rot.angle + by.angle);
rot.zoom *= by.zoom;
rot.size = new_ext.size;
rot.origin = new_ext.position + RealSize(rot.revX() ? rot.size.width : 0, rot.revY() ? rot.size.height : 0);
}
Rotater::~Rotater() {
rot = old; // restore
}
// ----------------------------------------------------------------------------- : RotatedDC
+8
View File
@@ -34,6 +34,8 @@ class Rotation {
inline RealSize getInternalSize() const { return trInv(size); }
/// The intarnal rectangle (origin at (0,0))
inline RealRect getInternalRect() const { return RealRect(RealPoint(0,0), getInternalSize()); }
/// The external rectangle (as passed to the constructor) == trNoNeg(getInternalRect())
RealRect getExternalRect() const;
/// Translate a size or length
inline double trS(double s) const { return s * zoom; }
@@ -67,6 +69,8 @@ class Rotation {
RealPoint origin; ///< tr(0,0)
double zoom; ///< Zoom factor, zoom = 2.0 means that 1 internal = 2 external
friend class Rotater;
/// Is the rotation sideways (90 or 270 degrees)?
// Note: angle & 2 == 0 for angle in {0, 180} and != 0 for angle in {90, 270)
inline bool sideways() const { return (angle & 2) != 0; }
@@ -91,11 +95,15 @@ class Rotation {
* @endcode
*/
class Rotater {
public:
/// Compose a rotation by onto the rotation rot
/** rot is restored when this object is destructed
*/
Rotater(Rotation& rot, const Rotation& by);
~Rotater();
private:
Rotation old;
Rotation& rot;
};
// ----------------------------------------------------------------------------- : RotatedDC
+1 -1
View File
@@ -9,7 +9,7 @@
/** @file util/string.hpp
*
* String and character utility functions and macros
* @brief String and character utility functions and macros
*/
// ----------------------------------------------------------------------------- : Includes
+53
View File
@@ -0,0 +1,53 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/tagged_string.hpp>
// ----------------------------------------------------------------------------- : Conversion to/from normal string
String untag(const String& str) {
bool intag = false;
String ret; ret.reserve(str.size());
FOR_EACH_CONST(c, str) {
if (c==_('<')) intag = true;
if (!intag) ret += c==_('\1') ? _('<') : c;
if (c==_('>')) intag = false;
}
return ret;
}
String untag_no_escape(const String& str) {
bool intag = false;
String ret; ret.reserve(str.size());
FOR_EACH_CONST(c, str) {
if (c==_('<')) intag = true;
if (!intag) ret += c;
if (c==_('>')) intag = false;
}
return ret;
}
String escape(const String& str) {
String ret; ret.reserve(str.size());
FOR_EACH_CONST(c, str) {
if (c==_('<')) ret += _('\1');
else ret += c;
}
return ret;
}
// ----------------------------------------------------------------------------- : Finding tags
size_t skip_tag(const String& str, size_t start) {
if (start >= str.size()) return String::npos;
size_t end = str.find_first_of(_('>'), start);
return end == String::npos ? String::npos : end + 1;
}
// ----------------------------------------------------------------------------- : Global operations
// ----------------------------------------------------------------------------- : Simplification
+105
View File
@@ -0,0 +1,105 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_UTIL_TAGGED_STRING
#define HEADER_UTIL_TAGGED_STRING
/** @file util/tagged_string.hpp
*
* @brief Utility for working with strings with tags
*/
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- : Conversion to/from normal string
/// Remove all tags from a string and convert escaped '<' back to normal '<'
/** e.g. "<sym>R</> something <i>(note)</>"
* becomes "R something (note)"
*/
String untag(const String&);
/// Remove all tags from a string, but doesn't convert back escape codes
/** untag_no_escape(x) = escape(untag(x)) */
String untag_no_escape(const String&);
/// Remove all tags from a string
/** In addition to what untag() does this function also removes <sep-soft>...</sep-soft>
*/
String untag_hide_sep(const String&);
/// Escapes a String by converting '>' to '\1'
String escape(const String&);
/// Convert old style </> close tags to new style </tag> tags
/** This style was used until 0.2.6 */
String fix_old_tags(const String&);
// ----------------------------------------------------------------------------- : Finding tags
/// Returns the position just beyond the tag starting at start
size_t skip_tag(const String& str, size_t start);
/// Find the position of the closing tag matching the tag at start
/** If not found returns String::npos
*/
size_t match_close_tag(const String& str, size_t start);
/// Return the tag at the given position (without the <>)
String tag_at(const String& str, size_t pos);
/// Return the tag at the given position (without the <>)
/** stops at '-', so for "<kw-a>" returns "kw" */
String tag_type_at(const String& str, size_t pos);
/// Matching close tag for a tag
String close_tag(const String& tag);
/// The matching close tag for an open tag and vice versa
String anti_tag(const String& tag);
// ----------------------------------------------------------------------------- : Global operations
/// Remove all instances of a tag and its close tag, but keep the contents.
/** tag doesn't have to be a complete tag, for example remove_tag(str, "<kw-")
* removes all tags starting with "<kw-".
*/
String remove_tag(const String& str, const String& tag);
/// Remove all instances of tags starting with tag
String remove_tag_exact(const String& str, const String& tag);
/// Remove all instances of a tag (including contents) from a string
/** tag doesn't have to be a complete tag, for example remove_tag_contents(str, "<kw-")
* removes all tags starting with "<kw-".
*/
String remove_tag_contents(const String& str, const String& tag);
// ----------------------------------------------------------------------------- : Simplification
/// Verify that a string is correctly tagged, if it is not, change it so it is
/** Ensures that:
* - All tags end, i.e. for each '<' there is a matching '>'
* - There are no tags containing '<'
*/
String verify_tagged(const String& str);
/// Simplify a tagged string
/** - merges adjecent open/close tags: "<tag></tag>" --> ""
* - removes overlapping tags: "<i>a<i>b</i>c</i>" --> "<i>abc</i>"
*/
String simplify_tagged(const String& str);
/// Simplify a tagged string by merging adjecent open/close tags "<tag></tag>" --> ""
String simplify_tagged_merge(const String& str);
/// Simplify overlapping formatting tags
String simplify_tagged_overlap(const String& str);
// ----------------------------------------------------------------------------- : EOF
#endif