Changeset 1848 in Sophya


Ignore:
Timestamp:
Jan 6, 2002, 7:00:35 PM (24 years ago)
Author:
ansari
Message:

Modification - ajout positionnement chaine pour DrawString - Reza 6/01/2001

Location:
trunk/SophyaPI/PI
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/pigraphgen.cc

    r1592 r1848  
    288288}
    289289
     290/* --Methode-- */
     291bool PIGraphicGen::CalcStringPositionShift(char const* s, int pos,
     292                                           int& dx, int& dy)
     293{
     294  dx = 0;
     295  dy = 0;
     296  cout << " PIGraphicGen::CalcStringPositionShift - DBG - pos= "
     297       << pos << endl;
     298  if (pos == 0) return(false);
     299  else {
     300    int posh = pos & PI_HorizontalPosition;
     301    int posv = pos & PI_VerticalPosition;
     302    if ((posh == PI_HorizontalLeft)  && (posv == PI_VerticalBottom))
     303      return(false);
     304    if (posh != PI_HorizontalLeft) {
     305      int wx = myFont.GetStringWidth(s);
     306      if (posh == PI_HorizontalCenter)  dx = wx/2;
     307      else if (posh == PI_HorizontalRight)  dx = wx;
     308      else wx = 0;
     309    }
     310    if (posv != PI_VerticalBottom) {
     311      int a,d;
     312      int wy = myFont.GetFontHeight(a, d);
     313      if (posv == PI_VerticalCenter)  dy = -wy/2;
     314      else if (posv == PI_VerticalTop)  dy = -wy;
     315      else dy = 0;
     316    }
     317    cout << " PIGraphicGen::CalcStringPositionShift - DBG2 - dx= "
     318         << dx << " dy=" << dy << endl;
     319    return(true);
     320  }
     321}
     322
     323
    290324//++
    291325// Titre        Sauvegarde et rappel des attributs graphiques
  • trunk/SophyaPI/PI/pigraphgen.h

    r1592 r1848  
    2828                 PI_StarMarker=9, PI_FStarMarker=10 };
    2929
    30 enum PIGrPosHorizontal { PI_HorizontalLeft = 0, PI_HorizontalCenter = 1,
    31                          PI_HorizontalRight = 2 };
    32 enum PIGrPosVertical { PI_VerticalBottom = 32, PI_VerticalCenter = 36,
    33                        PI_VerticalTop = 40 };
    3430
     31enum PIGrPosHorizontal // Flags de positionnement horizontal
     32// PI_HorizontalPosition regroupe l'ensemble des bits utilisables
     33     { PI_HorizontalLeft = 0x1, PI_HorizontalCenter = 0x2,               
     34       PI_HorizontalRight = 0x3, PI_HorizontalPosition = 0xF };
     35
     36enum PIGrPosVertical  // Flags de positionnement vertical
     37// PI_VerticalPosition regroupe l'ensemble des bits utilisables
     38     { PI_VerticalBottom = 0x10, PI_VerticalCenter = 0x20,
     39       PI_VerticalTop = 0x30, PI_VerticalPosition = 0xF0 };
     40
     41// Les differents modes de trace graphique disponible
    3542enum PIGOMode { PI_GOCopy = 0, PI_GOXOR = 1, PI_GOInvert = 2 };
    3643
     
    130137  virtual PIGrCoord  GetFontHeight(PIGrCoord& asc, PIGrCoord& desc);
    131138  virtual PIGrCoord  CalcStringWidth(char const* s);
     139  virtual bool       CalcStringPositionShift(char const* s, int pos, 
     140                                             int& dx, int& dy);
    132141
    133142// Sauvegarde des attributs graphiques
  • trunk/SophyaPI/PI/pigraphps.cc

    r1538 r1848  
    112112
    113113/* --Methode-- */
    114 void PIGraphicPS::DrawString(PIGrCoord x, PIGrCoord y, const char* s, int /*pos*/)
     114void PIGraphicPS::DrawString(PIGrCoord x, PIGrCoord y, const char* s, int pos)
    115115{
    116116if(mPSOut)
    117117  //  mPSOut->DrawString((double)x,(double)y,s,mFCol,mFAtt,mFSize); /* $CHECK$ PIFontSize ?? */
    118118  mPSOut->DrawString((double)x,(double)y,s,mFCol, myFont.GetFontName(),
    119                      myFont.GetFontAtt(),  myFont.GetFontSize()*0.9); /* $CHECK$  x 0.9 - Reza 4/11/99 */
     119                     myFont.GetFontAtt(),  myFont.GetFontSize(),
     120                     pos); /* $CHECK$  x 0.9 - Reza 4/11/99  - enleve 3/01/2002 */
    120121// Calculez la taille de la boite occupe par la fonte
    121122//  myFont.GetFontHeight(int& asc, int& desc)  Tres proche de myFont.GetFontSize() en principe
     
    125126
    126127/* --Methode-- */
    127 void PIGraphicPS::DrawOpaqueString(PIGrCoord x, PIGrCoord y, const char* s, int /*pos*/)
     128void PIGraphicPS::DrawOpaqueString(PIGrCoord x, PIGrCoord y, const char* s, int pos)
    128129{
    129130if(mPSOut)
    130131  //  mPSOut->DrawString((double)x,(double)y,s,mFCol,mFAtt,mFSize); /* $CHECK$ PIFontSize ?? */
    131132  mPSOut->DrawString((double)x,(double)y,s,mFCol, myFont.GetFontName(),
    132                      myFont.GetFontAtt(),  myFont.GetFontSize()*0.9);  /* $CHECK$  x 0.9 - Reza 4/11/99 */
     133                     myFont.GetFontAtt(),  myFont.GetFontSize(),
     134                     pos);  /* $CHECK$  x 0.9 - Reza 4/11/99 */
    133135// Idem taille ici
    134136return;
  • trunk/SophyaPI/PI/pigraphx.cc

    r1846 r1848  
    103103
    104104/* --Methode-- */
    105 void PIGraphicX::DrawString(PIGrCoord x, PIGrCoord y, const char* s, int /*pos*/)
    106 {
     105void PIGraphicX::DrawString(PIGrCoord x, PIGrCoord y, const char* s, int pos)
     106{
     107int dx, dy, xi, yi;
     108xi = x;  yi = y;
     109if (CalcStringPositionShift(s, pos, dx, dy)) {
     110  xi -= dx;  yi -= dy; }
    107111XDrawString (XtDisplay (MyWdg()),mWId,
    108                   DefGC(), (int)x, (int)y, s, strlen(s));
    109 return;
    110 }
    111 
    112 /* --Methode-- */
    113 void PIGraphicX::DrawOpaqueString(PIGrCoord x, PIGrCoord y, const char* s, int /*pos*/)
    114 {
     112                  DefGC(), xi, yi, s, strlen(s));
     113return;
     114}
     115
     116/* --Methode-- */
     117void PIGraphicX::DrawOpaqueString(PIGrCoord x, PIGrCoord y, const char* s, int pos)
     118{
     119int dx, dy, xi, yi;
     120xi = x;  yi = y;
     121if (CalcStringPositionShift(s, pos, dx, dy)) {
     122  xi -= dx;  yi -= dy; }
    115123XDrawImageString (XtDisplay (MyWdg()),mWId,
    116                   DefGC(), (int)x, (int)y, s, strlen(s));
     124                  DefGC(), xi, yi, s, strlen(s));
    117125return;
    118126}
  • trunk/SophyaPI/PI/psfile.cc

    r1846 r1848  
    130130/ff {findfont} bind def   /sf {setfont} bind def /scf {scalefont} bind def\n\
    131131/rl {rlineto} bind def    /tr {translate} bind def\n\
     132/rmv {rmoveto} bind def \n\
     133%% Trace de chaine avec justification diverse \n\
     134%% hxvyshstr  stack: TheString \n\
     135%% hx (x=r,c,l) Horizontal-X Right,Center,Left \n\
     136%% vy (y=t,c,b) Vertical-Y Top,Center,Bottom \n\
     137/hlvbshstr   %% Horizontal-left Vertical-Bottom justified \n\
     138{ gs 1 -1 sc show gr } bind def \n\
     139/hcvbshstr   %% Horizontal-Center Vertical-Bottom justified \n\
     140{ dup stringwidth pop 2 div neg  %% get minus(string length/2)  \n\
     141  0 rmoveto gs 1 -1 sc show gr } bind def \n\
     142/hrvbshstr   %% Horizontal-Right Vertical-Bottom justified \n\
     143{ dup stringwidth pop neg  %% get minus(string width)  \n\
     144  0 rmoveto gs 1 -1 sc show gr } bind def \n\
     145/hlvcshstr   %% Horizontal-left Vertical-Center justified \n\
     146{ dup stringwidth exch pop 2 div   %% get (string height)/2  \n\
     147  0 exch rmoveto gs 1 -1 sc show gr } bind def \n\
     148/hcvcshstr   %% Horizontal-Center Vertical-Center justified \n\
     149{ dup stringwidth 2 div exch 2 div neg   %% s_wy/2 -s_wx/2  \n\
     150  exch rmoveto gs 1 -1 sc show gr } bind def \n\
     151/hrvcshstr   %% Horizontal-Right Vertical-Center justified \n\
     152{ dup stringwidth 2 div exch neg   %% s_wy/2 -s_wx  \n\
     153  exch rmoveto gs 1 -1 sc show gr } bind def \n\
     154/hlvtshstr   %% Horizontal-left Vertical-Top justified \n\
     155{ dup stringwidth exch pop    %% get s_wy  \n\
     156  0 exch rmoveto gs 1 -1 sc show gr } bind def \n\
     157/hcvtshstr   %% Horizontal-Center Vertical-Top justified \n\
     158{ dup stringwidth exch 2 div neg   %% s_wy -s_wx/2  \n\
     159  exch rmoveto gs 1 -1 sc show gr } bind def \n\
     160/hrvtshstr   %% Horizontal-Right Vertical-Top justified \n\
     161{ dup stringwidth exch neg   %% s_wy -s_wx  \n\
     162  exch rmoveto gs 1 -1 sc show gr } bind def \n\
    132163%% Tx Ty X0 Y0 box\n\
    133164/box {tr 0 3 1 roll neg exch 0 0 3 index neg 0 0 m rl rl rl c} bind def\n\
     
    795826                           PIFontName FontName,
    796827                           PIFontAtt FontAtt,
    797                            int FontSize) {
     828                           int FontSize,
     829                           int pos) {
    798830    bool change = false;
    799831
     
    861893      setFontDone = true ;   // $CHECK$ - doit etre fait uniquement a ce moment
    862894    }
    863        
    864     fprintf(mPSFile, "gs %.2f Ux %.2f Uy m (%s) S gr\n", x, y, s) ;
     895    if (pos == 0)
     896      fprintf(mPSFile, "gs %.2f Ux %.2f Uy m (%s) S gr\n", x, y, s) ;
     897    else {
     898      int posh = pos & PI_HorizontalPosition;
     899      int posv = pos & PI_VerticalPosition;
     900      if ((posh == PI_HorizontalLeft)  && (posv == PI_VerticalBottom))
     901        fprintf(mPSFile, "gs %.2f Ux %.2f Uy m (%s) hlvbshstr gr\n",
     902                x, y, s) ;
     903      else {
     904        char ssvp = 'b';
     905        char sshp = 'l';
     906        if (posh != PI_HorizontalLeft) {
     907          if (posh == PI_HorizontalCenter)  sshp = 'c';
     908          else if (posh == PI_HorizontalRight)  sshp = 'r';
     909          else sshp = 'l';
     910        }
     911        if (posv != PI_VerticalBottom) {
     912          if (posv == PI_VerticalCenter)  ssvp = 'c';
     913          else if (posv == PI_VerticalTop)  ssvp = 't';
     914        }
     915        fprintf(mPSFile, "gs %.2f Ux %.2f Uy m (%s) h%cv%cshstr gr\n",
     916                x, y, s, sshp, ssvp) ;
     917      }
     918    }
    865919}
    866920
  • trunk/SophyaPI/PI/psfile.h

    r1846 r1848  
    112112                               PIFontName FontName = PI_DefaultFont,
    113113                               PIFontAtt FontAtt   = PI_NotDefFontAtt,
    114                                int FontSize        = 8);
     114                               int FontSize        = 8,
     115                               int pos = 0);
    115116    virtual void  DrawLine    (double x1, double y1, double x2, double y2,
    116117                               PIColors DrawColor  = PI_NotDefColor,
Note: See TracChangeset for help on using the changeset viewer.