/* ************************ Copyright Terrain Experts Inc. Terrain Experts Inc (TERREX) reserves all rights to this source code unless otherwise specified in writing by the President of TERREX. This copyright may be updated in the future, in which case that version supercedes this one. ------------------- Terrex Experts Inc. 4400 East Broadway #314 Tucson, AZ 85711 info@terrex.com Tel: (520) 323-7990 ************************ */ /* trpage_label.cpp Methods for the trpgLable object and its associated support structure including trpgTextStyle and trpgTextStyleTable. */ #include #include #include #include #include #include // *************** Text Style implementation trpgTextStyle::trpgTextStyle(void) { Reset(); } trpgTextStyle::~trpgTextStyle(void) { } void trpgTextStyle::Reset(void) { font = ""; bold = italic = underline = false; characterSize = float32(0.0042333333333); // 12 point in meter matId = -1; } void trpgTextStyle::SetMaterial(int inMatId) { matId = inMatId; } int trpgTextStyle::GetMaterial(void) const { return matId; } void trpgTextStyle::SetFont(std::string &inFont) { font = inFont; } const std::string *trpgTextStyle::GetFont(void) const { return &font; } void trpgTextStyle::SetBold(bool inBold) { bold = inBold; } bool trpgTextStyle::GetBold(void) const { return bold; } void trpgTextStyle::SetItalic(bool inItalic) { italic = inItalic; } bool trpgTextStyle::GetItalic(void) const { return italic; } void trpgTextStyle::SetUnderline(bool inUnder) { underline = inUnder; } bool trpgTextStyle::GetUnderline(void) const { return underline; } void trpgTextStyle::SetCharacterSize(float32 inSize) { characterSize = inSize; } float32 trpgTextStyle::GetCharacterSize(void) const { return characterSize; } // Write method bool trpgTextStyle::Write(trpgWriteBuffer &buf) { buf.Begin(TRPG_TEXT_STYLE); buf.Begin(TRPG_TEXT_STYLE_BASIC); buf.Add(font); buf.Add(bold); buf.Add(italic); buf.Add(underline); buf.Add(characterSize); buf.Add(matId); buf.End(); buf.End(); return true; } // TextStyle CB // Used to parse tokens from the text style structure. // If we do it this way it's easier to expand later. class textStyleCB : public trpgr_Callback { public: void * Parse(trpgToken,trpgReadBuffer &); trpgTextStyle *style; }; void * textStyleCB::Parse(trpgToken tok,trpgReadBuffer &buf) { std::string sVal; int iVal; float32 fVal; try { switch (tok) { case TRPG_TEXT_STYLE_BASIC: buf.Get(sVal); style->SetFont(sVal); buf.Get(iVal); style->SetBold((iVal ? true : false)); buf.Get(iVal); style->SetItalic((iVal ? true : false)); buf.Get(iVal); style->SetUnderline((iVal ? true : false)); buf.Get(fVal); style->SetCharacterSize(fVal); buf.Get(iVal); style->SetMaterial(iVal); break; default: break; } } catch (...) { return NULL; } return style; } // Read from a buffer bool trpgTextStyle::Read(trpgReadBuffer &buf) { Reset(); trpgr_Parser parse; textStyleCB textStyleCb; textStyleCb.style = this; parse.AddCallback(TRPG_TEXT_STYLE_BASIC,&textStyleCb,false); parse.Parse(buf); return isValid(); } bool trpgTextStyle::isValid(void) const { // Need to have a font designation at least if (font.size() > 0) return true; return false; } bool trpgTextStyle::operator == (const trpgTextStyle& in) const { if (font.compare(in.font) != 0) return false; if (bold != in.bold || italic != in.italic || underline != in.underline) return false; if(fabs(double(characterSize - in.characterSize)) > 0.0001) return false; if (matId != in.matId) return false; return true; } // ******************* Text Style Table implementation trpgTextStyleTable::trpgTextStyleTable() { Reset(); } trpgTextStyleTable::~trpgTextStyleTable() { } void trpgTextStyleTable::Reset() { styles.resize(0); } bool trpgTextStyleTable::isValid() const { for (unsigned int i=0;i= (int)styles.size()) return NULL; return &styles[id]; } bool trpgTextStyleTable::Write(trpgWriteBuffer &buf) { if (!isValid()) return false; buf.Begin(TRPG_TEXT_STYLE_TABLE); // Number of styles int numStyle = styles.size(); buf.Add((int32)numStyle); // Write the styles for (unsigned int i=0;iSetType(trpgSupportStyle::SupportType(iVal)); buf.Get(iVal); style->SetMaterial(iVal); break; default: break; } } catch (...) { return NULL; } return style; } // Read from a buffer bool trpgSupportStyle::Read(trpgReadBuffer &buf) { Reset(); trpgr_Parser parse; supportStyleCB supportStyleCb; supportStyleCb.style = this; parse.AddCallback(TRPG_SUPPORT_STYLE_BASIC,&supportStyleCb,false); parse.Parse(buf); return isValid(); } bool trpgSupportStyle::isValid(void) const { return true; } bool trpgSupportStyle::operator == (const trpgSupportStyle& in) const { if (type != in.type || matId != in.matId) return false; return true; } // ******************* Support Style Table implementation trpgSupportStyleTable::trpgSupportStyleTable() { Reset(); } trpgSupportStyleTable::~trpgSupportStyleTable() { } void trpgSupportStyleTable::Reset() { styles.resize(0); } bool trpgSupportStyleTable::isValid() const { for (unsigned int i=0;i= (int)styles.size()) return NULL; return &styles[id]; } bool trpgSupportStyleTable::Write(trpgWriteBuffer &buf) { if (!isValid()) return false; buf.Begin(TRPG_SUPPORT_STYLE_TABLE); // Number of styles int numStyle = styles.size(); buf.Add((int32)numStyle); // Write the styles for (unsigned int i=0;iSetFontStyle(iVal); buf.Get(iVal); property->SetSupport(iVal); buf.Get(ival); property->SetType(trpgLabelProperty::LabelType(ival)); break; default: break; } } catch (...) { return NULL; } return property; } // Read from a buffer bool trpgLabelProperty::Read(trpgReadBuffer &buf) { Reset(); trpgr_Parser parse; labelPropertyCB labelPropertyCb; labelPropertyCb.property = this; parse.AddCallback(TRPG_LABEL_PROPERTY_BASIC,&labelPropertyCb,false); parse.Parse(buf); return isValid(); } bool trpgLabelProperty::isValid(void) const { return supportId != -1 && fontId != -1 && type >=0 && type < MaxLabelType; } bool trpgLabelProperty::operator == (const trpgLabelProperty& in)const { if (fontId != in.fontId || supportId != in.supportId || type != in.type) return false; return true; } // ******************* Label Property Table implementation trpgLabelPropertyTable::trpgLabelPropertyTable() { Reset(); } trpgLabelPropertyTable::~trpgLabelPropertyTable() { } void trpgLabelPropertyTable::Reset() { properties.resize(0); } bool trpgLabelPropertyTable::isValid() const { for (unsigned int i=0;i= (int)properties.size()) return NULL; return &properties[id]; } bool trpgLabelPropertyTable::Write(trpgWriteBuffer &buf) { if (!isValid()) return false; buf.Begin(TRPG_LABEL_PROPERTY_TABLE); // Number of styles int numProperty = properties.size(); buf.Add((int32)numProperty); // Write the properties for (unsigned int i=0;i *trpgLabel::GetSupports() const { return &supports; } bool trpgLabel::Write(trpgWriteBuffer &buf) { buf.Begin(TRPG_LABEL); buf.Add(propertyId); buf.Add(text); buf.Add(alignment); buf.Add(tabSize); buf.Add(scale); buf.Add(thickness); buf.Add(desc); buf.Add(url); buf.Add(location); buf.Add((int)supports.size()); for (unsigned i=0;i