| René Nyffenegger's collection of things on the web | |
|
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Text [Ming wrapper class] | ||
The sourceText.h
#ifndef TEXT_H
#define TEXT_H
#include <string>
#include "ming.h"
#include "Font.h"
#include "Action.h"
#include "Character_.h"
/*
Glyph Text vs Device Text
-------------------------
Glyph Text:
o Look identical on all platform (because font definition is embedded in
swf)
o Will be anti-aliased
o Defined through DefineFont or DefineFont2
Device Text:
o Not anti-aliased
o Drawn dependent on platform
o Either specified with a font name to be sought on platform OR
using pre defined font names that will be tried to be mapped to
available fonts on platform. These font names are:
o _sans
o _serif
o _typewriter
o and others for japanese and chinese characters
o Defined through DefineFontInfo
Static Text vs Dynamic Text
---------------------------
Dynamic Text
o used through TextField class
o can be changed at runtime (through setting the
text member)
o Can be made editable (through calling (ReadOnly(false))
o Has formatting capabilites (like HTML like formatting,
call (HTML(true))
Static Text
o Only advantige of Dynamic Text over Dynamic Text is: it can
be positioned exactly.
o Normally rendered as glyph text. Behaviour can be changed
in embedding HTML through a 'devicefont' tag option
*/
class Text : public Character_ {
public:
Text(Font font, int size, float x, float y, std::string const& txt, byte r, byte g, byte b, byte a=0xff);
/* Returns advance */
void Add (std::string const& txt);
void Kerning (int k); // ???? Kerning = Spacing ????
void Coordinates(float x, float y);
void Color (byte r, byte g, byte b, byte a=0xff);
void setFont (Font const& font);
void Size (int size);
float Width (std::string const& txt);
protected:
SWFText text_;
protected:
// HACK?
virtual SWFBlock_s* swf_block() const;
};
#endif
Text.cpp
#include "Text.h"
Text::Text(Font font, int size, float x, float y, std::string const& txt, byte r, byte g, byte b, byte a) {
text_ = newSWFText2();
setFont (font);
Size (size);
Color (r,g,b,a);
Coordinates(x, y);
//SWFText_setSpacing(text_, 0);
Add (txt);
}
float Text::Width(std::string const& txt) {
return SWFText_getStringWidth(text_, reinterpret_cast<const unsigned char*>(txt.c_str()));
}
void Text::Add(std::string const& txt) {
//int ret;
SWFText_addString(text_, /*reinterpret_cast<const unsigned char*>(*/txt.c_str()/*)*/, 0);
//SWFText_addString(text_, "bla bla", NULL);
//return ret;
}
void Text::Kerning(int k) {
SWFText_setSpacing(text_, k);
}
// ???? Kerning = Spacing ????
void Text::Coordinates(float x, float y) {
SWFText_setXY(text_, x, y);
}
void Text::Color(byte r, byte g, byte b, byte a) {
SWFText_setColor(text_, r, g, b, a);
}
void Text::setFont(Font const& font) {
SWFText_setFont(text_, font.font_);
}
void Text::Size(int size) {
SWFText_setHeight(text_, size);
}
SWFBlock_s* Text::swf_block() const {
return reinterpret_cast<SWFBlock_s*>(text_);
}
Examples
The following examples demonstrate this class:
|