Logo Search packages:      
Sourcecode: magics++ version File versions  Download package

MAGICS_NO_EXPORT void PostScriptDriver::renderText ( const Text &  text  )  const [private, virtual]

renders text strings

This method renders given text strings.

Note:
As of version 2.0 there are two forms of describing text in Text.
Todo:
Underlining of text
See also:
Text
Parameters:
text object containing the strings and their description

Reimplemented from magics::BaseDriver.

Definition at line 735 of file PostScriptDriver.cc.

References magics::lowerCase(), setNewColour(), special(), and specialPS().

{
      if(text.empty()) return;
      const vector<NiceText>& niceT = text.getNiceText();
      if(niceT.empty()) return;

      fstream *ps = getStream();
      streamsize ss = ps->precision(2);

      *ps << text.getJustification() << " SHA " << text.getVerticalAlign() << " SVA ";

      vector<NiceText>::const_iterator niceText = text.textBegin();
      vector<NiceText>::const_iterator niceTextEnd = text.textEnd();

      int u=0;
      ostringstream all_text;
      for(;niceText<niceTextEnd;)
      {
            all_text << (*niceText).text();
            niceText++;
            u++;
      }

      niceText = text.textBegin();
      int count = 0;

      for(;niceText<niceTextEnd;)
      {
            const MagFont magfont = (*niceText).font();

            const std::set<string>& styles = magfont.styles();
            string style = "";
            if(styles.find("bold") != styles.end()) style = "bold";
            if(styles.find("italic") != styles.end()) style += "italic";
            if(style == "") style = "normal";
            const string lowFont = lowerCase(magfont.name()+"_"+style);
            fontMapIter iter = FontMap_.find(lowFont);

            const bool underlined = (styles.find("underlined") != styles.end()) ? true : false;

            int font;
            if(iter!=FontMap_.end())
                  font = iter->second.id;
            else
            {
                  font = 0; // if not found get default
                  Log::warning() << "PostScriptDriver: Font "<< lowFont << " is not registered! Default font is used."<< endl;
            }

            const float dheight = convertCM(magfont.size());

            setNewColour(magfont.colour());

            float offset = 0;
            float height = dheight;
//          if((*niceText).elevation()==NORMAL)           {offset = 0;             height = dheight;}
//          else if((*niceText).elevation()==SUPERSCRIPT) {offset = (dheight*0.6); height = dheight*0.5;}
//          else if((*niceText).elevation()==SUBSCRIPT)   {offset = (dheight*0.6); height = dheight*0.5;}

            *ps << font << " " << static_cast<int>(height) << " SF ";

            // plot strings
            string textCommand = (text.getBlanking()) ? "TB" : "T";
            if(underlined) textCommand = "TU";

            const int len = (*niceText).text().length()+1;
            char pp[len];
            strcpy(pp, (*niceText).text().c_str());
            char *p = pp;
            bool specialChar = false;
            ostringstream tmp;
            ostringstream special;

            while(*p)
            {
              if(specialChar)
              {
                  if( *p == ';')
                  {
                        tmp << specialPS(special.str());
                        specialChar=false;
                  }
                  else
                  {
                        special << *p;
                  }
              }
              else if ( *p == '(')    {tmp << "\\(";}
              else if ( *p == ')')    {tmp << "\\)";}
              else if ( *p == '\\')   {tmp << "\\\\";}
              else if ( *p & 0x80)    {p++;tmp << *p;}   // temp fix for multibyte char (degree sign)
              else if ( *p == '&')    {p++;
                                       if(*p)
                                 {
                                    if(*p=='#')
                                    {
                                          tmp << "\\";
                                          specialChar=true;
                                    }
                                    else tmp<<"&"<<*p;
                                 }
                                       else tmp<<"&";}
              else                    {tmp << *p;}
              p++;
            }

        const string showCommand = (underlined) ? "ushow" : "show";
        unsigned int noTexts = text.size();
        for(unsigned int nT=0;nT<noTexts;nT++)  // for all string CO-ORDINATES
        {
            if(niceText == text.textBegin())
            {
                  const float x0 = projectX(text[nT].x());
                  const float y0 = projectY(text[nT].y()) + offset;

                  if(u>1)
                  {
                        *ps <<"gs "<< x0 << " " << y0 << " t ("<< all_text.str() << ") stringwidth pop HA mul VA Height mul moveto "
                            << "("<<tmp.str()<< ") "<<showCommand<<"\n";
                  }
                  else
                  {

      /*
      Log::dev()<< "  PS TEXT >>> " << (*niceText).text()<<" " <<text.getAngle()<< "  ver:";
      if (text.getVerticalAlign()==MBASE)      Log::dev()<< "MBASE";
      else if (text.getVerticalAlign()==MTOP)  Log::dev()<< "MTOP";
      else if (text.getVerticalAlign()==MHALF) Log::dev()<< "MHALF";
      else if (text.getVerticalAlign()==MBOTTOM) Log::dev()<< "MBOTTOM";
      else Log::dev()<< "???";
      cout<<"  x: "<< text[nT].x()<< "   y: "<< text[nT].y()<< endl;
      */
                        const float an = 360.-(text.getAngle()*57.29577951);
                        if(an==0 || an==360)
                              *ps <<"gs "<< x0 << " " << y0 << " t ("<<tmp.str()<< ") 0 0 "<<textCommand<<"\n";
                        else
                              *ps <<"gs "<< x0 << " " << y0 << " t "<<an<< " ro ("<<tmp.str()<< ") 0 0 "<<textCommand<<"\n";
                  }
            }
            else
            {
                  if(offset!=0)
                  {
                        *ps << "gs 0 "<<offset<<" t\n";
                  }
                  *ps << "("<<tmp.str()<< ") "<<showCommand<<"\n";
                  if(offset!=0)
                  {
                        *ps << "gr\n";
                  }
            }
            count++;
            if (niceText+1 == text.textEnd()) *ps <<"gr\n";
         }
         niceText++;
      } // endfor all nicetexts
      ps->precision(ss);
      currentColour_ = Colour("none");
}


Generated by  Doxygen 1.6.0   Back to index