1 /*=====================================================================
5 Classe Graphic2d_Paragraph
12 =====================================================================*/
14 #define PRO12982 //GG_230498
15 // Take into account the underlining in calculation of
18 #define PRO11004 //GG_051197
19 // The contour of the paragraph is not rectangle
21 #define PRO11005 //GG_131197
22 // Text can't be seen in mode Highlight.
24 #define PRO11041 //GG_201197
25 // Modification of SetCurrentFont(...,aHScale,aWScale)
26 // to parameterize the size of the text.
28 #define PRO12320//GG_120297
29 // Compose texts depending on the summary height of the
30 // chain of characters.
32 #define PERF //GG_200898
33 // The MinMax are now computed at the right time and no more
34 // soon an attribute has change
35 // (see the redefined method ComputeMinMax()).
37 #include <Graphic2d_Paragraph.ixx>
38 #include <Aspect_WindowDriver.hxx>
39 #include <TShort_Array1OfShortReal.hxx>
41 #include <Graphic2d_Primitive.pxx>
47 #define MAXALIGNMENT 16
48 #define MAXUNDERLINE 2
49 #define TEXT_DESCRIPTOR(row,column,color,font,align,underline) \
50 ((column) | (row)*MAXCOLUMN | (color)*MAXCOLUMN*MAXROW | \
51 (font)*MAXCOLUMN*MAXROW*MAXCOLOR | \
52 (align)*MAXCOLUMN*MAXROW*MAXCOLOR*MAXFONT | \
53 (underline)*MAXCOLUMN*MAXROW*MAXCOLOR*MAXFONT*MAXALIGNMENT)
54 #define TEXT_POSITION(descriptor) ((descriptor)&(MAXCOLUMN*MAXROW-1))
55 #define TEXT_COLUMN(descriptor) ((descriptor)&(MAXCOLUMN-1))
56 #define TEXT_ROW(descriptor) (((descriptor)/MAXCOLUMN)&(MAXROW-1))
57 #define TEXT_COLOR(descriptor) (((descriptor)/(MAXCOLUMN*MAXROW))&(MAXCOLOR-1))
58 #define TEXT_FONT(descriptor) (((descriptor)/(MAXCOLUMN*MAXROW*MAXCOLOR))&(MAXFONT-1))
59 #define TEXT_ALIGNMENT(descriptor) (((descriptor)/(MAXCOLUMN*MAXROW*MAXCOLOR*MAXFONT))&(MAXALIGNMENT-1))
60 #define TEXT_UNDERLINE(descriptor) (((descriptor)/(MAXCOLUMN*MAXROW*MAXCOLOR*MAXFONT*MAXALIGNMENT))&(MAXUNDERLINE-1))
62 Graphic2d_Paragraph::Graphic2d_Paragraph
63 (const Handle(Graphic2d_GraphicObject)& aGraphicObject,
64 const Standard_Real X, const Standard_Real Y,
65 const Quantity_PlaneAngle anAngle,
66 const Aspect_CardinalPoints anOffset,
67 const Quantity_Factor aScale)
68 : Graphic2d_Primitive (aGraphicObject),
69 myX( Standard_ShortReal( X ) ),
70 myY( Standard_ShortReal( Y ) ),
76 myAngle(Standard_ShortReal( anAngle )),
77 myScale(Standard_ShortReal( aScale )),
79 myTextDescriptorList(),
80 myTextXpositionList(),
81 myTextYpositionList(),
87 while (myAngle < 0.) myAngle += Standard_ShortReal( 2. * M_PI );
88 while (myAngle >= 2. * M_PI) myAngle -= Standard_ShortReal( 2. * M_PI );
94 SetFrameColorIndex() ;
95 SetFrameWidthIndex() ;
96 SetHidingColorIndex() ;
97 SetCurrentColorIndex() ;
98 SetCurrentFontIndex() ;
99 SetCurrentAlignment() ;
100 SetCurrentUnderline() ;
103 void Graphic2d_Paragraph::SetHidingColorIndex (const Standard_Integer anIndex)
106 myHidingColorIndex = anIndex;
110 void Graphic2d_Paragraph::SetFrameColorIndex (const Standard_Integer anIndex) {
112 myFrameColorIndex = anIndex;
116 void Graphic2d_Paragraph::SetFrameWidthIndex (const Standard_Integer anIndex) {
118 myFrameWidthIndex = anIndex;
122 void Graphic2d_Paragraph::SetCurrentColorIndex (const Standard_Integer anIndex) {
124 myCurrentColorIndex = anIndex;
128 void Graphic2d_Paragraph::SetCurrentFontIndex (const Standard_Integer anIndex,const Quantity_Length aHScale,const Quantity_Length aWScale) {
130 myCurrentFontIndex = anIndex;
131 myCurrentFontHScale = (aHScale > 0.) ?
132 Standard_ShortReal( aHScale ) : Standard_ShortReal( 1. );
133 myCurrentFontWScale =
134 (aWScale > 0.) ? Standard_ShortReal( aWScale ) : myCurrentFontHScale;
138 void Graphic2d_Paragraph::SetCurrentAlignment (const Graphic2d_TypeOfAlignment anAlignment) {
140 myCurrentAlignment = anAlignment;
143 void Graphic2d_Paragraph::SetCurrentUnderline (const Standard_Boolean isUnderlined) {
145 myCurrentUnderline = isUnderlined;
148 void Graphic2d_Paragraph::SetSlant (const Quantity_PlaneAngle aSlant) {
150 mySlant = Standard_ShortReal( aSlant );
151 while (mySlant < 0.) mySlant += Standard_ShortReal( 2. * M_PI );
152 while (mySlant >= 2. * M_PI) mySlant -= Standard_ShortReal( 2. * M_PI );
155 void Graphic2d_Paragraph::SetSpacing (const Quantity_Ratio aSpacing) {
157 mySpacing = Standard_ShortReal( aSpacing );
159 myMinX = myMinY = ShortRealLast ();
160 myMaxX = myMaxY = ShortRealFirst ();
166 void Graphic2d_Paragraph::SetMargin (const Quantity_Length aMargin) {
169 myMargin = Standard_ShortReal( aMargin * myScale );
171 myMargin = Standard_ShortReal( aMargin );
174 myMinX = myMinY = ShortRealLast ();
175 myMaxX = myMaxY = ShortRealFirst ();
181 Standard_Boolean Graphic2d_Paragraph::IsZoomable () const {
187 void Graphic2d_Paragraph::SetZoomable (const Standard_Boolean aFlag) {
189 myIsZoomable = aFlag;
191 myMinX = myMinY = ShortRealLast ();
192 myMaxX = myMaxY = ShortRealFirst ();
198 void Graphic2d_Paragraph::AddText (const TCollection_ExtendedString &aText,
199 const Standard_Integer aRow,
200 const Standard_Integer aColumn) {
201 Standard_Integer i,length = myTextDescriptorList.Length() ;
202 Standard_Integer row = (aRow > 0) ? Min(aRow,MAXROW-1) : MAXROW-1 ;
203 Standard_Integer column = (aColumn > 0) ? Min(aColumn,MAXCOLUMN-1) : MAXCOLUMN-1 ;
204 Standard_Integer descriptor = TEXT_DESCRIPTOR(row,column,myCurrentColorIndex,
205 myCurrentFontIndex,myCurrentAlignment,myCurrentUnderline) ;
206 Standard_Integer the_position = TEXT_POSITION(descriptor) ;
208 for( i=1 ; i<=length ; i++ ) {
209 Standard_Integer cur_position =
210 TEXT_POSITION(myTextDescriptorList.Value(i)) ;
211 if( the_position == cur_position ) {
212 myTextDescriptorList.SetValue(i,descriptor) ;
213 myTextStringList.SetValue(i,aText) ;
214 myTextHScaleList.SetValue(i,myCurrentFontHScale);
215 myTextWScaleList.SetValue(i,myCurrentFontWScale);
218 if( the_position < cur_position ) break ;
222 if( aRow <= 0 || aColumn <= 0 ) {
225 row = TEXT_ROW(myTextDescriptorList.Value(length))+1 ;
226 row = Min(row,MAXROW-1) ;
233 if( row == TEXT_ROW(myTextDescriptorList.Value(length)) ) {
234 column = TEXT_COLUMN(myTextDescriptorList.Value(length))+1 ;
235 column = Min(column,MAXCOLUMN-1) ;
243 descriptor = TEXT_DESCRIPTOR(row,column,myCurrentColorIndex,
244 myCurrentFontIndex,myCurrentAlignment,myCurrentUnderline) ;
246 myTextDescriptorList.Append(descriptor) ;
247 myTextStringList.Append(aText) ;
248 myTextXpositionList.Append(0.) ;
249 myTextYpositionList.Append(0.) ;
250 myTextFheightList.Append(0.) ;
251 myTextFoffsetList.Append(0.) ;
252 myTextHScaleList.Append(myCurrentFontHScale) ;
253 myTextWScaleList.Append(myCurrentFontWScale) ;
255 if( aRow <= 0 || aColumn <= 0 ) {
258 row = TEXT_ROW(myTextDescriptorList.Value(i-1))+1 ;
259 row = Min(row,MAXROW-1) ;
266 if( row == TEXT_ROW(myTextDescriptorList.Value(i-1)) ) {
267 column = TEXT_COLUMN(myTextDescriptorList.Value(i-1))+1 ;
268 column = Min(column,MAXCOLUMN-1) ;
276 descriptor = TEXT_DESCRIPTOR(row,column,myCurrentColorIndex,
277 myCurrentFontIndex,myCurrentAlignment,myCurrentUnderline) ;
279 myTextDescriptorList.InsertBefore(i,descriptor) ;
280 myTextStringList.InsertBefore(i,aText) ;
281 myTextXpositionList.InsertBefore(i,0.) ;
282 myTextYpositionList.InsertBefore(i,0.) ;
283 myTextFheightList.InsertBefore(i,0.) ;
284 myTextFoffsetList.InsertBefore(i,0.) ;
285 myTextHScaleList.InsertBefore(i,myCurrentFontHScale);
286 myTextWScaleList.InsertBefore(i,myCurrentFontWScale);
289 myMinX = myMinY = ShortRealLast ();
290 myMaxX = myMaxY = ShortRealFirst ();
297 void Graphic2d_Paragraph::ChangeText (const TCollection_ExtendedString &aText,
298 const Standard_Integer aRow,
299 const Standard_Integer aColumn) {
300 Standard_Integer i,length = myTextDescriptorList.Length() ;
302 Standard_Integer descriptor = TEXT_DESCRIPTOR(aRow,aColumn,0,0,0,0) ;
303 Standard_Integer the_position = TEXT_POSITION(descriptor) ;
305 for( i=1 ; i<=length ; i++ ) {
306 Standard_Integer cur_position =
307 TEXT_POSITION(myTextDescriptorList.Value(i)) ;
308 if( the_position == cur_position ) {
309 myTextStringList.SetValue(i,aText) ;
311 myMinX = myMinY = ShortRealLast ();
312 myMaxX = myMaxY = ShortRealFirst ();
322 void Graphic2d_Paragraph::Clear() {
324 myTextDescriptorList.Clear() ;
325 myTextStringList.Clear() ;
326 myTextXpositionList.Clear() ;
327 myTextYpositionList.Clear() ;
328 myTextFheightList.Clear() ;
329 myTextFoffsetList.Clear() ;
330 myTextHScaleList.Clear() ;
331 myTextWScaleList.Clear() ;
333 myMinX = myMinY = ShortRealLast ();
334 myMaxX = myMaxY = ShortRealFirst ();
340 void Graphic2d_Paragraph::Draw (const Handle(Graphic2d_Drawer)& aDrawer) {
341 //Standard_Integer descriptor,row = 0 ;
342 Standard_Integer descriptor ;
343 TCollection_ExtendedString atext ;
344 Standard_ShortReal x = 0, y = 0, dx, dy,
345 sina = Standard_ShortReal( Sin(myAngle) ),
346 cosa = Standard_ShortReal( Cos(myAngle) );
347 //Standard_Integer i,j,lrow,length = myTextDescriptorList.Length() ;
348 Standard_Integer i,length = myTextDescriptorList.Length() ;
349 Standard_Boolean IsIn = Standard_False;
350 Standard_ShortReal hscale,wscale,scale = (myIsZoomable) ? myScale*aDrawer->Scale() : myScale;
352 Standard_ShortReal rscale = 1.;
354 Standard_ShortReal rscale = 1./myScale;
358 if( (myMaxX < myMinX) || (myMaxY < myMinY) ) {
359 if( !ComputeMinMax() ) return;
362 if( myWidth <= 0. ) {
367 static TShort_Array1OfShortReal theXarray(1,5) ;
368 static TShort_Array1OfShortReal theYarray(1,5) ;
370 // We have to draw frame without drawer's scaling
371 // because drawer's scale will betaken into consideration
372 // in MapPolylineFromTo(), MapPolygonFromTo().
373 // The same concerns test's position.
375 rscale = aDrawer->Scale();
376 if (! myGOPtr->IsTransformed ()) {
377 IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY);
379 if( myFrameColorIndex > 0 || myHidingColorIndex >= 0 ) {
380 theXarray.SetValue(1,myX+XROTATE(myXoffset,myYoffset)/rscale) ;
381 theYarray.SetValue(1,myY+YROTATE(myXoffset,myYoffset)/rscale) ;
382 theXarray.SetValue(2,myX+XROTATE(myXoffset+myWidth,myYoffset)/rscale) ;
383 theYarray.SetValue(2,myY+YROTATE(myXoffset+myWidth,myYoffset)/rscale) ;
384 theXarray.SetValue(3,myX+XROTATE(myXoffset+myWidth,myYoffset-myHeight)/rscale) ;
386 theYarray.SetValue(3,myY+YROTATE(myXoffset+myWidth,myYoffset-myHeight)/rscale) ;
388 theYarray.SetValue(3,YROTATE(myXoffset+myWidth,myYoffset-myHeight)/rscale) ;
390 theXarray.SetValue(4,myX+XROTATE(myXoffset,myYoffset-myHeight)/rscale) ;
391 theYarray.SetValue(4,myY+YROTATE(myXoffset,myYoffset-myHeight)/rscale) ;
392 theXarray.SetValue(5,myX+XROTATE(myXoffset,myYoffset)/rscale) ;
393 theYarray.SetValue(5,myY+YROTATE(myXoffset,myYoffset)/rscale) ;
395 if( myHidingColorIndex >= 0 ) {
396 aDrawer->SetHidingTextAttrib(-1,myHidingColorIndex,
397 myFrameColorIndex,myFrameWidthIndex,
398 -1,0.,1.,1.,Standard_False);
399 aDrawer->MapPolygonFromTo(theXarray, theYarray, 4);
401 aDrawer->SetFramedTextAttrib(-1,myFrameColorIndex,
402 myFrameWidthIndex,-1,0.,1.,1.,Standard_False);
403 aDrawer->MapPolylineFromTo(theXarray, theYarray, 5);
406 if( myHidingColorIndex >= 0 ) {
407 aDrawer->SetPolyAttrib(myHidingColorIndex,0,Standard_False) ;
408 aDrawer->MapPolygonFromTo(theXarray, theYarray, 4);
410 if( myFrameColorIndex > 0 ) {
411 aDrawer->SetLineAttrib(myFrameColorIndex,0,myFrameWidthIndex) ;
412 aDrawer->MapPolylineFromTo(theXarray, theYarray, 5);
416 for( i=1 ; i<=length ; i++ ) {
417 descriptor = myTextDescriptorList.Value(i) ;
418 atext = myTextStringList.Value(i) ;
419 dx = myXoffset + myTextXpositionList.Value(i);
420 dy = myYoffset + myTextYpositionList.Value(i);
421 x = XROTATE(dx,dy)/rscale ; y = YROTATE(dx,dy)/rscale;
422 hscale = scale*myTextHScaleList.Value(i);
423 wscale = scale*myTextWScaleList.Value(i);
424 aDrawer->SetTextAttrib(TEXT_COLOR(descriptor),
425 TEXT_FONT(descriptor),mySlant,hscale,wscale,
426 TEXT_UNDERLINE(descriptor));
427 aDrawer->MapTextFromTo(atext,myX+x,myY+y,
428 myAngle,0.,0.,Aspect_TOT_SOLID);
432 gp_GTrsf2d aTrsf = myGOPtr->Transform ();
433 Standard_ShortReal minx,miny,maxx,maxy;
434 MinMax(minx,maxx,miny,maxy);
435 IsIn = aDrawer->IsIn (minx,maxx,miny,maxy);
437 Standard_Real A = Standard_Real (myX);
438 Standard_Real B = Standard_Real (myY);
439 Standard_Real C = Standard_Real (myAngle);
440 Standard_Real cosa = Cos (C);
441 Standard_Real sina = Sin (C);
443 aTrsf.Transforms (A, B);
445 // To calculate new aperture angles
446 // the calculation is done on trigonometric circle
447 // and in this case translation is not taken into account.
448 aTrsf.SetValue (1, 3, 0.0);
449 aTrsf.SetValue (2, 3, 0.0);
450 aTrsf.Transforms (cosa, sina);
452 Standard_ShortReal tscale = 1.;
453 Standard_ShortReal x0 = myXoffset;
454 Standard_ShortReal y0 = myYoffset;
455 Standard_ShortReal w = myWidth;
456 Standard_ShortReal h = myHeight;
457 C = atan2(sina,cosa);
458 Standard_ShortReal angle = Standard_ShortReal (C);
459 if ( myIsZoomable ) {
460 tscale = Standard_ShortReal( Sqrt(cosa*cosa + sina*sina) );
461 scale *= Standard_ShortReal( tscale );
462 x0 *= tscale; y0 *= tscale;
463 w *= tscale; h *= tscale;
465 cosa = Cos(C) ; sina = Sin(C) ;
466 if( myFrameColorIndex > 0 || myHidingColorIndex >= 0 ) {
467 dx = Standard_ShortReal( XROTATE(x0,y0)/rscale );
468 dy = Standard_ShortReal( YROTATE(x0,y0)/rscale );
469 theXarray.SetValue( 1, x + dx );
470 theYarray.SetValue( 1, y + dy );
471 dx = Standard_ShortReal( XROTATE(x0+w,y0)/rscale );
472 dy = Standard_ShortReal( YROTATE(x0+w,y0)/rscale );
473 theXarray.SetValue(2,x+dx) ; theYarray.SetValue(2,y+dy) ;
474 dx = Standard_ShortReal( XROTATE(x0+w,y0-h)/rscale );
475 dy = Standard_ShortReal( YROTATE(x0+w,y0-h)/rscale );
476 theXarray.SetValue(3,x+dx) ;
477 theYarray.SetValue(3,y+dy) ;
478 dx = Standard_ShortReal( XROTATE(x0,y0-h)/rscale );
479 dy = Standard_ShortReal( YROTATE(x0,y0-h)/rscale );
480 theXarray.SetValue(4,x+dx) ; theYarray.SetValue(4,y+dy) ;
481 dx = Standard_ShortReal( XROTATE(x0,y0)/rscale );
482 dy = Standard_ShortReal( YROTATE(x0,y0)/rscale );
483 theXarray.SetValue(5,x+dx) ; theYarray.SetValue(5,y+dy) ;
485 if( myHidingColorIndex >= 0 ) {
486 aDrawer->SetHidingTextAttrib(-1,myHidingColorIndex,
487 myFrameColorIndex,myFrameWidthIndex,
488 -1,0.,1.,1.,Standard_False);
489 aDrawer->MapPolygonFromTo(theXarray, theYarray, 4);
491 aDrawer->SetFramedTextAttrib(-1,myFrameColorIndex,
492 myFrameWidthIndex,-1,0.,1.,1.,Standard_False);
493 aDrawer->MapPolylineFromTo(theXarray, theYarray, 5);
496 if( myHidingColorIndex >= 0 ) {
497 aDrawer->SetPolyAttrib(myHidingColorIndex,0,Standard_False) ;
498 aDrawer->MapPolygonFromTo(theXarray, theYarray, 4);
500 if( myFrameColorIndex > 0 ) {
501 aDrawer->SetLineAttrib(myFrameColorIndex,0,myFrameWidthIndex) ;
502 aDrawer->MapPolylineFromTo(theXarray, theYarray, 5);
506 Standard_ShortReal tx,ty;
507 for( i=1 ; i<=length ; i++ ) {
508 descriptor = myTextDescriptorList.Value(i) ;
509 atext = myTextStringList.Value(i) ;
510 dx = x0 + myTextXpositionList.Value(i)*tscale ;
511 dy = y0 + myTextYpositionList.Value(i)*tscale ;
512 tx = Standard_ShortReal( XROTATE(dx,dy)/rscale );
513 ty = Standard_ShortReal( YROTATE(dx,dy)/rscale );
514 hscale = scale*myTextHScaleList.Value(i) ;
515 wscale = scale*myTextWScaleList.Value(i) ;
516 aDrawer->SetTextAttrib(TEXT_COLOR(descriptor),
517 TEXT_FONT(descriptor),mySlant,hscale,wscale,
518 TEXT_UNDERLINE(descriptor));
519 aDrawer->MapTextFromTo(atext,x+tx,y+ty,
520 angle,0.,0.,Aspect_TOT_SOLID);
527 Standard_Boolean Graphic2d_Paragraph::Pick (const Standard_ShortReal X,
528 const Standard_ShortReal Y,
529 const Standard_ShortReal aPrecision,
530 const Handle(Graphic2d_Drawer)& aDrawer)
532 Standard_Boolean theStatus = Standard_False;
533 Standard_ShortReal TX = X, TY = Y;
535 if (IsInMinMax (X, Y, aPrecision)) {
536 if (myGOPtr->IsTransformed ()) {
537 gp_GTrsf2d aTrsf = (myGOPtr->Transform ()).Inverted ();
538 Standard_Real RX = Standard_Real (X), RY = Standard_Real (Y);
539 aTrsf.Transforms (RX, RY);
540 TX = Standard_ShortReal (RX); TY = Standard_ShortReal (RY);
543 Standard_ShortReal cosa = Standard_ShortReal( Cos(-myAngle) );
544 Standard_ShortReal sina = Standard_ShortReal( Sin(-myAngle) );
545 Standard_ShortReal dx = TX-myX;
546 Standard_ShortReal dy = TY-myY;
547 Standard_ShortReal x = XROTATE(dx,dy);
548 Standard_ShortReal y = YROTATE(dx,dy);
550 theStatus = x >= myXoffset - aPrecision
551 && x <= myXoffset + myWidth + aPrecision
552 && y >= -myYoffset - aPrecision
553 && y <= myHeight -myYoffset + aPrecision;
559 void Graphic2d_Paragraph::Size ( Quantity_Length &aWidth,
560 Quantity_Length &aHeight) const {
566 void Graphic2d_Paragraph::Position( Quantity_Length &X,
567 Quantity_Length &Y) const {
573 Aspect_CardinalPoints Graphic2d_Paragraph::Offset( Quantity_Length &X,
574 Quantity_Length &Y) const {
582 Quantity_PlaneAngle Graphic2d_Paragraph::Angle() const {
587 Quantity_PlaneAngle Graphic2d_Paragraph::Slant() const {
592 Quantity_PlaneAngle Graphic2d_Paragraph::Spacing() const {
597 Quantity_PlaneAngle Graphic2d_Paragraph::Margin() const {
602 Standard_Integer Graphic2d_Paragraph::HidingColorIndex() const {
604 return myHidingColorIndex;
607 Standard_Integer Graphic2d_Paragraph::FrameColorIndex() const {
609 return myFrameColorIndex;
612 Standard_Integer Graphic2d_Paragraph::FrameWidthIndex() const {
614 return myFrameWidthIndex;
617 TCollection_ExtendedString Graphic2d_Paragraph::Text(
618 const Standard_Integer aRank,
619 Standard_Integer &aRow,
620 Standard_Integer &aColumn,
621 Standard_Integer &aColorIndex,
622 Standard_Integer &aFontIndex,
623 Graphic2d_TypeOfAlignment &anAlignment) const {
625 if( aRank <= 0 || aRank > myTextDescriptorList.Length() ) {
626 Standard_OutOfRange::Raise ("Bad Text rank");
629 Standard_Integer descriptor = myTextDescriptorList.Value(aRank) ;
630 aRow = TEXT_ROW(descriptor) ;
631 aColumn = TEXT_COLUMN(descriptor) ;
632 aColorIndex = TEXT_COLOR(descriptor) ;
633 aFontIndex = TEXT_FONT(descriptor) ;
634 anAlignment = Graphic2d_TypeOfAlignment(TEXT_ALIGNMENT(descriptor)) ;
636 return myTextStringList.Value(aRank) ;
639 Standard_Boolean Graphic2d_Paragraph::TextSize ( const Standard_Integer aRank,
640 Quantity_Length &aWidth, Quantity_Length &aHeight,
641 Quantity_Length &anXoffset, Quantity_Length &anYoffset) const {
642 Handle(Graphic2d_Drawer) aDrawer = Drawer();
644 if( aRank <= 0 || aRank > myTextDescriptorList.Length() ) {
645 Standard_OutOfRange::Raise ("Bad Text rank");
648 if( !aDrawer.IsNull() && aDrawer->IsWindowDriver() ) {
649 Standard_Integer descriptor = myTextDescriptorList.Value(aRank) ;
650 Standard_ShortReal wscale,hscale,scale = (myIsZoomable) ?
651 myScale * aDrawer->Scale() : myScale;
652 Standard_ShortReal width,height,xoffset,yoffset;
653 TCollection_ExtendedString atext = myTextStringList.Value(aRank) ;
654 hscale = scale*myTextHScaleList.Value(aRank);
655 wscale = scale*myTextWScaleList.Value(aRank);
656 aDrawer->SetTextAttrib(TEXT_COLOR(descriptor),TEXT_FONT(descriptor),
657 mySlant,hscale,wscale,TEXT_UNDERLINE(descriptor));
659 aDrawer->GetTextSize(atext,width,height,xoffset,yoffset);
664 return Standard_True;
666 aWidth = aHeight = anXoffset = anYoffset = 0.;
667 return Standard_False;
672 Standard_Integer Graphic2d_Paragraph::Length() const {
674 return myTextStringList.Length();
677 Standard_Integer Graphic2d_Paragraph::MaxRow() const {
678 Standard_Integer descriptor,i,n;
680 for( i=1,n=0 ; i<=myTextDescriptorList.Length() ; i++ ) {
681 descriptor = myTextDescriptorList.Value(i) ;
682 n = Max(n,TEXT_ROW(descriptor)) ;
688 Standard_Integer Graphic2d_Paragraph::MaxColumn() const {
689 Standard_Integer descriptor,i,n;
691 for( i=1,n=0 ; i<=myTextDescriptorList.Length() ; i++ ) {
692 descriptor = myTextDescriptorList.Value(i) ;
693 n = Max(n,TEXT_COLUMN(descriptor)) ;
700 Standard_Boolean Graphic2d_Paragraph::ComputeMinMax() {
702 void Graphic2d_Paragraph::Update() {
704 Handle(Graphic2d_Drawer) aDrawer = Drawer();
705 Standard_Boolean status = Standard_False;
707 if( !aDrawer.IsNull() && aDrawer->IsWindowDriver() ) {
708 Standard_ShortReal rscale = 1.;
710 rscale = aDrawer->Scale();
712 Standard_Integer descriptor,row = 0 ;
713 TCollection_ExtendedString atext ;
714 Standard_ShortReal x, y, dx, dy,
715 sina = Standard_ShortReal( Sin(myAngle) ),
716 cosa = Standard_ShortReal( Cos(myAngle) );
717 Standard_Integer i,j,lrow,length = myTextDescriptorList.Length() ;
718 Standard_ShortReal hscale,wscale,scale =
719 (myIsZoomable) ? myScale*aDrawer->Scale() : myScale;
720 Standard_ShortReal twidth = 0.,theight = 0.,txoffset = 0.,tyoffset = 0.;
721 Standard_ShortReal lwidth = 0.,lheight = 0.,loffset = 0.;
722 myWidth = myHeight = 0. ;
723 for( i=1,j=lrow=0 ; i<=length ; i++ ) { // Passe 1, gets texts minmax
724 descriptor = myTextDescriptorList.Value(i) ;
725 atext = myTextStringList.Value(i) ;
726 hscale = scale*myTextHScaleList.Value(i) ;
727 wscale = scale*myTextWScaleList.Value(i) ;
728 aDrawer->SetTextAttrib(TEXT_COLOR(descriptor),
729 TEXT_FONT(descriptor),mySlant,hscale,wscale,
730 TEXT_UNDERLINE(descriptor));
731 if( aDrawer->GetTextSize(atext,twidth,theight,txoffset,tyoffset) ) {
733 static TCollection_ExtendedString hletter("Hp");
734 Standard_ShortReal hwidth,hheight,hxoffset,hyoffset;
735 if(( status = aDrawer->GetTextSize(hletter,hwidth,hheight,
736 hxoffset,hyoffset) )) {
737 theight = Max(hheight-hyoffset,theight-tyoffset);
738 tyoffset = Max(hyoffset,tyoffset);
741 Standard_ShortReal fheight,fbheight,fslant;
742 aDrawer->GetFontSize(fheight,fbheight,fslant);
743 theight = fheight + fbheight; tyoffset = 0.;
746 myTextXpositionList.SetValue(i,twidth) ;
747 if( row == TEXT_ROW(descriptor) ) {
748 lwidth += twidth ; lheight = Max(lheight,theight) ;
749 loffset = Max(loffset,tyoffset);
752 if( j > 1 ) lheight += mySpacing*lheight*(row-lrow) ;
756 myTextYpositionList.SetValue(j,lheight) ;
757 myWidth = Max(myWidth,lwidth) ;
758 myHeight += lheight ;
760 lwidth = twidth ; lheight = theight ; loffset = tyoffset;
761 lrow = row ; row = TEXT_ROW(descriptor) ; j = i ;
767 if( j > 1 ) lheight += mySpacing*lheight*(row-lrow) ;
771 myTextYpositionList.SetValue(j,lheight) ;
772 myWidth = Max(myWidth,lwidth) ;
773 myHeight += lheight ;
778 myWidth += Standard_ShortReal( 2.*myMargin );
779 myHeight += Standard_ShortReal( 2.*myMargin );
784 for( i=1 ; i<=length ; i++ ) { // Passe 2,sets texts position
785 descriptor = myTextDescriptorList.Value(i) ;
786 twidth = myTextXpositionList.Value(i) ;
787 if( row != TEXT_ROW(descriptor) ) {
788 theight = myTextYpositionList.Value(i) ;
789 x = myMargin ; y -= theight ;
790 row = TEXT_ROW(descriptor) ;
792 switch (TEXT_ALIGNMENT(descriptor)) {
793 case Graphic2d_TOA_TOPLEFT:
794 case Graphic2d_TOA_MEDIUMLEFT:
795 case Graphic2d_TOA_BOTTOMLEFT:
796 case Graphic2d_TOA_LEFT:
798 case Graphic2d_TOA_TOPCENTER:
799 case Graphic2d_TOA_MEDIUMCENTER:
800 case Graphic2d_TOA_BOTTOMCENTER:
801 case Graphic2d_TOA_CENTER:
802 x = Standard_ShortReal( (myWidth-twidth)/2. );
804 case Graphic2d_TOA_TOPRIGHT:
805 case Graphic2d_TOA_MEDIUMRIGHT:
806 case Graphic2d_TOA_BOTTOMRIGHT:
807 case Graphic2d_TOA_RIGHT:
808 x = myWidth-twidth-myMargin ;
811 myTextXpositionList.SetValue(i,x*rscale) ;
812 myTextYpositionList.SetValue(i,y*rscale) ;
817 case Aspect_CP_North:
818 myXoffset = Standard_ShortReal( -myWidth/2. ); myYoffset = 0. ;
820 case Aspect_CP_NorthEast:
821 myXoffset = -myWidth ; myYoffset = 0. ;
824 myXoffset = -myWidth ; myYoffset = Standard_ShortReal( myHeight/2. );
826 case Aspect_CP_SouthEast:
827 myXoffset = -myWidth ; myYoffset = myHeight ;
829 case Aspect_CP_South:
830 myXoffset = Standard_ShortReal( -myWidth/2. ); myYoffset = myHeight ;
832 case Aspect_CP_SouthWest:
833 myXoffset = 0. ; myYoffset = myHeight ;
836 myXoffset = 0.; myYoffset = Standard_ShortReal( myHeight/2. );
838 case Aspect_CP_NorthWest:
839 myXoffset = 0. ; myYoffset = 0. ;
841 case Aspect_CP_Center:
842 myXoffset = Standard_ShortReal( -myWidth/2. );
843 myYoffset = Standard_ShortReal( myHeight/2. );
846 myMinX = myMinY = ShortRealLast();
847 myMaxX = myMaxY = ShortRealFirst();
849 dx = XROTATE(myXoffset,myYoffset) ;
850 dy = YROTATE(myXoffset,myYoffset) ;
851 myMinX = Min(myMinX,myX+dx) ;
852 myMinY = Min(myMinY,myY+dy) ;
853 myMaxX = Max(myMaxX,myX+dx) ;
854 myMaxY = Max(myMaxY,myY+dy) ;
856 dx = XROTATE(myWidth+myXoffset,myYoffset) ;
857 dy = YROTATE(myWidth+myXoffset,myYoffset) ;
858 myMinX = Min(myMinX,myX+dx) ;
859 myMinY = Min(myMinY,myY+dy) ;
860 myMaxX = Max(myMaxX,myX+dx) ;
861 myMaxY = Max(myMaxY,myY+dy) ;
863 dx = XROTATE(myWidth+myXoffset,-myHeight+myYoffset) ;
864 dy = YROTATE(myWidth+myXoffset,-myHeight+myYoffset) ;
865 myMinX = Min(myMinX,myX+dx) ;
866 myMinY = Min(myMinY,myY+dy) ;
867 myMaxX = Max(myMaxX,myX+dx) ;
868 myMaxY = Max(myMaxY,myY+dy) ;
870 dx = XROTATE(myXoffset,-myHeight+myYoffset) ;
871 dy = YROTATE(myXoffset,-myHeight+myYoffset) ;
872 myMinX = Min(myMinX,myX+dx) ;
873 myMinY = Min(myMinY,myY+dy) ;
874 myMaxX = Max(myMaxX,myX+dx) ;
875 myMaxY = Max(myMaxY,myY+dy) ;
884 cout << "*Graphic2d_Paragraph::ComputeMinMax() returns wrong values*" << endl;
893 void Graphic2d_Paragraph::Save(Aspect_FStream& aFStream) const