#ifdef __GNUG__ #pragma implementation #endif #include "ProtVersion.h" #ifndef VERSION_B #include #include "protean/ProtMedium.h" #include "protean/ProtMediumData.h" #include "containers/PooledString.voidPtr.VHMap.h" #include "protean/ProtStackC.h" #include "protean/ProtBlockC.h" #include "protean/ProtEvlDataC.h" #include "protean/ProtEvalC.h" #include "containers/voidPtr.SLList.h" #include "protean/ProtSDataC.h" #include "protean/ProtSchemaC.h" #include "protean/ProtType.h" #else #include #include "proteus/ProtMedium.h" #include "proteus/ProtMediumData.h" #include "proteus/ProtType.h" #endif #ifdef VERSION_B #include "proteus/ProtSchemaB.h" #else #include "protean/ProtSchemaC.h" #endif #include "common/assert.h" #include "TextInterface1.h" ProtMedium* TextInterface1::_medium = NULL; TextInterface1::TextInterface1(ProtDocument* newDoc, ProtClient* client, istream& infile, ostream& estream) #ifdef VERSION_B : PROTPRES(newDoc, setSchema(setMedium(), infile, estream), client) #else : PROTPRES(newDoc, setMedium(), infile, estream, client) #endif {} TextInterface1::~TextInterface1() { #ifdef VERSION_B delete _schema; #endif } ProtSchema* TextInterface1::schema() const { return (_schema); } ProtMedium* TextInterface1::medium() const { return (_medium); } PROTSCHEMA* TextInterface1::setSchema(ProtMedium* medium, istream& infile, ostream& estream) { _schema = new PROTSCHEMA(medium, infile, estream); return (_schema); } const int TextInterface1::_AlignTypeNValues = 4; const char* TextInterface1::_AlignTypeNames[_AlignTypeNValues+1]= {"blockjustify", "centerjustify", "rightjustify", "leftjustify", NULL}; const int TextInterface1::_AlignType[_AlignTypeNValues]= {JUSTIFY,CENTERED,RIGHT,LEFT}; double TextInterface1::width(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("WIDTH", false); #else static unsigned int pos = _medium->getStAttr("WIDTH", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, pos); #else ProtValue v = ((PROTNODE*)n)->attrValue(pos); #endif return (v.realVal()); } double TextInterface1::actualWidth(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("WIDTH", true); #else static unsigned int pos = _medium->getStAttr("WIDTH", true)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, pos); #else ProtValue v = ((PROTNODE*)n)->attrValue(pos); #endif return (v.realVal()); } double TextInterface1::left(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("LEFT", false); #else static unsigned int pos = _medium->getStAttr("LEFT", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, pos); #else ProtValue v = ((PROTNODE*)n)->attrValue(pos); #endif return (v.realVal()); } double TextInterface1::actualLeft(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("LEFT", true); #else static unsigned int pos = _medium->getStAttr("LEFT", true)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, pos); #else ProtValue v = ((PROTNODE*)n)->attrValue(pos); #endif return (v.realVal()); } double TextInterface1::right(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("LEFT", false); #else static unsigned int pos = _medium->getStAttr("LEFT", false)->id(); #endif #ifdef VERSION_B static const ProtStoredAttrA* ext = _medium->getStAttr("WIDTH", false); #else static unsigned int ext = _medium->getStAttr("WIDTH", false)->id(); #endif #ifdef VERSION_B ProtValue extVal = getValue(n, ext); #else ProtValue extVal = ((PROTNODE*)n)->attrValue(ext); #endif #ifdef VERSION_B ProtValue posVal = getValue(n, pos); #else ProtValue posVal = ((PROTNODE*)n)->attrValue(pos); #endif double d = posVal.realVal() + extVal.realVal(); return (d); } double TextInterface1::actualRight(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("LEFT", true); #else static unsigned int pos = _medium->getStAttr("LEFT", true)->id(); #endif #ifdef VERSION_B static const ProtStoredAttrA* ext = _medium->getStAttr("WIDTH", true); #else static unsigned int ext = _medium->getStAttr("WIDTH", true)->id(); #endif #ifdef VERSION_B ProtValue extVal = getValue(n, ext); #else ProtValue extVal = ((PROTNODE*)n)->attrValue(ext); #endif #ifdef VERSION_B ProtValue posVal = getValue(n, pos); #else ProtValue posVal = ((PROTNODE*)n)->attrValue(pos); #endif double d = posVal.realVal() + extVal.realVal(); return (d); } double TextInterface1::hmiddle(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("LEFT", false); #else static unsigned int pos = _medium->getStAttr("LEFT", false)->id(); #endif #ifdef VERSION_B static const ProtStoredAttrA* ext = _medium->getStAttr("WIDTH", false); #else static unsigned int ext = _medium->getStAttr("WIDTH", false)->id(); #endif #ifdef VERSION_B ProtValue extVal = getValue(n, ext); #else ProtValue extVal = ((PROTNODE*)n)->attrValue(ext); #endif #ifdef VERSION_B ProtValue posVal = getValue(n, pos); #else ProtValue posVal = ((PROTNODE*)n)->attrValue(pos); #endif double d = posVal.realVal() + extVal.realVal()/2.0; return (d); } double TextInterface1::actualHmiddle(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("LEFT", true); #else static unsigned int pos = _medium->getStAttr("LEFT", true)->id(); #endif #ifdef VERSION_B static const ProtStoredAttrA* ext = _medium->getStAttr("WIDTH", true); #else static unsigned int ext = _medium->getStAttr("WIDTH", true)->id(); #endif #ifdef VERSION_B ProtValue extVal = getValue(n, ext); #else ProtValue extVal = ((PROTNODE*)n)->attrValue(ext); #endif #ifdef VERSION_B ProtValue posVal = getValue(n, pos); #else ProtValue posVal = ((PROTNODE*)n)->attrValue(pos); #endif double d = posVal.realVal() + extVal.realVal()/2.0; return (d); } double TextInterface1::height(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("HEIGHT", false); #else static unsigned int pos = _medium->getStAttr("HEIGHT", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, pos); #else ProtValue v = ((PROTNODE*)n)->attrValue(pos); #endif return (v.realVal()); } double TextInterface1::actualHeight(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("HEIGHT", true); #else static unsigned int pos = _medium->getStAttr("HEIGHT", true)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, pos); #else ProtValue v = ((PROTNODE*)n)->attrValue(pos); #endif return (v.realVal()); } double TextInterface1::top(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("TOP", false); #else static unsigned int pos = _medium->getStAttr("TOP", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, pos); #else ProtValue v = ((PROTNODE*)n)->attrValue(pos); #endif return (v.realVal()); } double TextInterface1::actualTop(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("TOP", true); #else static unsigned int pos = _medium->getStAttr("TOP", true)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, pos); #else ProtValue v = ((PROTNODE*)n)->attrValue(pos); #endif return (v.realVal()); } double TextInterface1::bottom(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("TOP", false); #else static unsigned int pos = _medium->getStAttr("TOP", false)->id(); #endif #ifdef VERSION_B static const ProtStoredAttrA* ext = _medium->getStAttr("HEIGHT", false); #else static unsigned int ext = _medium->getStAttr("HEIGHT", false)->id(); #endif #ifdef VERSION_B ProtValue extVal = getValue(n, ext); #else ProtValue extVal = ((PROTNODE*)n)->attrValue(ext); #endif #ifdef VERSION_B ProtValue posVal = getValue(n, pos); #else ProtValue posVal = ((PROTNODE*)n)->attrValue(pos); #endif double d = posVal.realVal() + extVal.realVal(); return (d); } double TextInterface1::actualBottom(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("TOP", true); #else static unsigned int pos = _medium->getStAttr("TOP", true)->id(); #endif #ifdef VERSION_B static const ProtStoredAttrA* ext = _medium->getStAttr("HEIGHT", true); #else static unsigned int ext = _medium->getStAttr("HEIGHT", true)->id(); #endif #ifdef VERSION_B ProtValue extVal = getValue(n, ext); #else ProtValue extVal = ((PROTNODE*)n)->attrValue(ext); #endif #ifdef VERSION_B ProtValue posVal = getValue(n, pos); #else ProtValue posVal = ((PROTNODE*)n)->attrValue(pos); #endif double d = posVal.realVal() + extVal.realVal(); return (d); } double TextInterface1::vmiddle(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("TOP", false); #else static unsigned int pos = _medium->getStAttr("TOP", false)->id(); #endif #ifdef VERSION_B static const ProtStoredAttrA* ext = _medium->getStAttr("HEIGHT", false); #else static unsigned int ext = _medium->getStAttr("HEIGHT", false)->id(); #endif #ifdef VERSION_B ProtValue extVal = getValue(n, ext); #else ProtValue extVal = ((PROTNODE*)n)->attrValue(ext); #endif #ifdef VERSION_B ProtValue posVal = getValue(n, pos); #else ProtValue posVal = ((PROTNODE*)n)->attrValue(pos); #endif double d = posVal.realVal() + extVal.realVal()/2.0; return (d); } double TextInterface1::actualVmiddle(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* pos = _medium->getStAttr("TOP", true); #else static unsigned int pos = _medium->getStAttr("TOP", true)->id(); #endif #ifdef VERSION_B static const ProtStoredAttrA* ext = _medium->getStAttr("HEIGHT", true); #else static unsigned int ext = _medium->getStAttr("HEIGHT", true)->id(); #endif #ifdef VERSION_B ProtValue extVal = getValue(n, ext); #else ProtValue extVal = ((PROTNODE*)n)->attrValue(ext); #endif #ifdef VERSION_B ProtValue posVal = getValue(n, pos); #else ProtValue posVal = ((PROTNODE*)n)->attrValue(pos); #endif double d = posVal.realVal() + extVal.realVal()/2.0; return (d); } double TextInterface1::blankLines(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* attr = _medium->getStAttr("BLANKLINES", false); #else static unsigned int attr = _medium->getStAttr("BLANKLINES", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, attr); #else ProtValue v = ((PROTNODE*)n)->attrValue(attr); #endif return ((double) v.realVal()); } double TextInterface1::indent(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* attr = _medium->getStAttr("INDENT", false); #else static unsigned int attr = _medium->getStAttr("INDENT", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, attr); #else ProtValue v = ((PROTNODE*)n)->attrValue(attr); #endif return ((double) v.realVal()); } AlignType TextInterface1::justify(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* attr = _medium->getStAttr("JUSTIFY", false); #else static unsigned int attr = _medium->getStAttr("JUSTIFY", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, attr); #else ProtValue v = ((PROTNODE*)n)->attrValue(attr); #endif return ((AlignType) v.intVal()); } double TextInterface1::lineWidth(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* attr = _medium->getStAttr("LINEWIDTH", false); #else static unsigned int attr = _medium->getStAttr("LINEWIDTH", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, attr); #else ProtValue v = ((PROTNODE*)n)->attrValue(attr); #endif return ((double) v.realVal()); } double TextInterface1::fontSize(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* attr = _medium->getStAttr("FONTSIZE", false); #else static unsigned int attr = _medium->getStAttr("FONTSIZE", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, attr); #else ProtValue v = ((PROTNODE*)n)->attrValue(attr); #endif return ((double) v.realVal()); } PooledString TextInterface1::fontFamily(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* attr = _medium->getStAttr("FONTFAMILY", false); #else static unsigned int attr = _medium->getStAttr("FONTFAMILY", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, attr); #else ProtValue v = ((PROTNODE*)n)->attrValue(attr); #endif return ((PooledString) v.psVal()); } bool TextInterface1::italic(PROTNODE* n) { #ifdef VERSION_B static const ProtStoredAttrA* attr = _medium->getStAttr("ITALIC", false); #else static unsigned int attr = _medium->getStAttr("ITALIC", false)->id(); #endif #ifdef VERSION_B ProtValue v = getValue(n, attr); #else ProtValue v = ((PROTNODE*)n)->attrValue(attr); #endif return ((bool) v.boolVal()); } extern PooledString upperRoman(ProtPres*, double); static ProtValue uroman(ProtPres* pres, const ProtValue* args, bool& valid) { valid = true; PooledString s(upperRoman(pres,args[0].realVal())); return(ProtValue(s)); } extern PooledString rgbFN(ProtPres*, double, double, double); static ProtValue rgb(ProtPres* pres, const ProtValue* args, bool& valid) { valid = true; PooledString s(rgbFN(pres,args[0].realVal() ,args[1].realVal() ,args[2].realVal())); return(ProtValue(s)); } extern PooledString getURLfromAnchor(ProtPres*, ProtPresNode*); static ProtValue getURL(ProtPres* pres, const ProtValue* args, bool& valid) { valid = true; PooledString s(getURLfromAnchor(pres,args[0].nodeVal())); return(ProtValue(s)); } ProtMedium* TextInterface1::setMedium() { if (_medium != NULL) return (_medium); _medium = new ProtMedium ("TextInterface1", 1, 7, 2, 3); _medium->storeDimenAttrSet("height", "vertpos", "top", "bottom", "vmiddle"); _medium->storeDimenAttrSet("width", "horizpos", "left", "right", "hmiddle"); ProtEnum* justAlignType = new ProtEnum("AlignType", _AlignTypeNValues, AlignTypeNames(), _AlignType); const ProtType* primTypes0[1]; primTypes0[0] = &ProtPString; _medium->storePrimitive(new ProtPrimitive(PooledString("TEXT"), createTextNode, setTextNode, 1, primTypes0)); _medium->storeBoolAttr("italic", false); _medium->storeStrAttr("fontFamily", "times"); _medium->storeNumAttr("fontSize", 12); _medium->storeNumAttr("lineWidth", 72.0); _medium->storeEnumAttr("justify", justAlignType, LEFT); _medium->storeNumAttr("indent", 0.0); _medium->storeNumAttr("blankLines", 0.0); const ProtType* uromanTypes[1]; uromanTypes[0] = &ProtNumber; _medium->storeFunction (new ProtFunction("UROMAN", &ProtPString, 1, uromanTypes, &uroman)); const ProtType* rgbTypes[3]; rgbTypes[0] = &ProtNumber; rgbTypes[1] = &ProtNumber; rgbTypes[2] = &ProtNumber; _medium->storeFunction (new ProtFunction("RGB", &ProtPString, 3, rgbTypes, &rgb)); const ProtType* getURLTypes[1]; getURLTypes[0] = &ProtNodeType; _medium->storeFunction (new ProtFunction("GETURL", &ProtPString, 1, getURLTypes, &getURL)); return(_medium); }