StringBox.c File Reference

#include "StringBox.h"
#include "Xcall1.h"
#include "GetProperty.h"
#include "Axes.h"
#include "math_graphics.h"
#include "PloEch.h"
#include "MALLOC.h"
#include "CurrentObjectsManagement.h"
#include "ObjectSelection.h"

Include dependency graph for StringBox.c:

Go to the source code of this file.

Functions

void getStringBbox (char *string, int center[2], int rect[4])
void callXstringL (char *string, int posX, int posY, int boundingRect[4])
void getStringBox (char **text, double textPos[2], int textDim[2], BOOL autoSize, double userSize[2], double angle, int fontId, int fontSize, double corners[4][2])
void getStringsRect (StringMatrix *strMat, int textPos[2], Vect2iMatrix *stringPosition, int boundingBox[4][2])
void getStringsRectSized (StringMatrix *strMat, int textPos[2], Vect2iMatrix *stringPosition, int boundingBox[4][2], int userSize[2], int *newFontSize)
void getStringsPositions (StringMatrix *strMat, int *fontId, int *fontSize, int textPos[2], BOOL autoSize, int textSize[2], BOOL centerPos, double angle, Vect2iMatrix *stringPosition, int boundingBox[4][2])
void getTextBoundingBox (sciPointObj *pText, int cornPix[4][2], double corners[4][2])
void getTextAabb (sciPointObj *pText, int rectPix[4], int cornPix[4][2])
void rotateBoundingBox (int boundingBox[4][2], int center[2], double angle)
void translateBoundingBox (int boundingBox[4][2], int trans[2])
int getStringVerticalSpace (void)
int getStringHorizontalSpace (void)
BOOL isFittingInCell (char *string, int cellWidth, int cellHeight)
void getStringPositionTranslation (BOOL centeredPos, int textSize[2], int bbox[4][2], int trans[2])
int computeSuitableFont (StringMatrix *strMat, Vect2iMatrix *stringPosition)


Function Documentation

void callXstringL ( char *  string,
int  posX,
int  posY,
int  boundingRect[4] 
)

This is a wrapping of the function C2F(dr)("xstringl",... It should be prefered to xstringl because it is working even in drawlater mode. The parent Subwindow of the text must be the current axes.

Definition at line 25 of file StringBox.c.

References C2F, dr(), L, PD0, PI0, SCI_SUBWIN, sciGetCurrentFigure(), sciGetFirstTypedSelectedSon(), and updateScaleIfRequired().

00026 {
00027   sciPointObj * parentSubWin = sciGetFirstTypedSelectedSon( sciGetCurrentFigure(), SCI_SUBWIN ) ;
00028 
00029   updateScaleIfRequired( parentSubWin ) ;
00030 
00031   /* now we can call xstringl */
00032   C2F(dr)("xstringl",string,&posX,&posY,boundingRect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00033 
00034 }

Here is the call graph for this function:

int computeSuitableFont ( StringMatrix strMat,
Vect2iMatrix stringPosition 
)

get the largest font which can be used to fit the strings in the array.

Parameters:
strMat Set of strings which try to fit in stringPosition.
position of the cells in which the strings need to fit.

Definition at line 485 of file StringBox.c.

References C2F, dr(), getMatNbCol(), getMatNbRow(), getStrMatElement(), getVect2iMatElement(), height, isFittingInCell(), L, PD0, PI0, string, v, and width.

Referenced by getStringsRectSized().

00486 {
00487   int nbRow = getMatNbRow( strMat ) ;
00488   int nbCol = getMatNbCol( strMat ) ;
00489   int largestFont  ;
00490   int smallestFont ;
00491   int i ;
00492   int j ; 
00493   integer curFont[2]  ;
00494   integer verbose = 0 ;
00495   integer v ;
00496 
00497   C2F(dr)("xget","font",&verbose,curFont,&v,PI0,PI0,PI0,PD0,PD0,PD0,PD0,5L,5L) ;
00498 
00499   /* the largest font is the minimum of all largest font which can be used for each cells */
00500   /* initializeit with the largest font the driver can display */
00501   C2F(dr)( "xfontmxs","", &smallestFont, &largestFont, PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L ) ;
00502 
00503   /* set the largest font */
00504   C2F(dr)("xset","font",&(curFont[0]),&largestFont,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00505 
00506   for ( i = 0 ; i < nbRow ; i++ )
00507   {
00508     for ( j = 0 ; j < nbCol ; j++ )
00509     {
00510       int  * blCorner = getVect2iMatElement( stringPosition, i    , j     ) ;
00511       int  * urCorner = getVect2iMatElement( stringPosition, i + 1, j + 1 ) ;
00512       char * string   = getStrMatElement( strMat, i, j ) ;
00513       int width  = urCorner[0] - blCorner[0] ;
00514       int height = urCorner[1] - blCorner[1] ;
00515       while ( !isFittingInCell( string, width, height ) )
00516       {
00517         largestFont-- ;
00518         if ( largestFont == smallestFont )
00519         {
00520           /* we reach the minimum size, no need to continue */
00521           C2F(dr)("xset","font",&curFont[0],&curFont[1],PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ; 
00522           return smallestFont ;
00523         }
00524         /* set the new font */
00525         C2F(dr)("xset","font",&(curFont[0]),&largestFont,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00526       }
00527     }
00528   }
00529 
00530   /* return to the previous font */
00531   C2F(dr)("xset","font",&curFont[0],&curFont[1],PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
00532   return largestFont ;
00533 
00534 }

Here is the call graph for this function:

Here is the caller graph for this function:

void getStringBbox ( char *  string,
int  center[2],
int  rect[4] 
)

return the bounding rectangle of a string.

Parameters:
string bounded string
center Position where the string ought to be displayed.
rect vector containing the upper left point and the width and height of the bounding box : [x,y,w,h].

Definition at line 20 of file StringBox.c.

References bsiz, C2F, dr(), L, PD0, and PI0.

Referenced by drawStringInCell(), getStringHorizontalSpace(), getStringsRect(), getStringVerticalSpace(), and isFittingInCell().

00021 {
00022   C2F(dr)("xstringl",string,&(center[0]),&(center[1]),rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,9L,bsiz);
00023 }

Here is the call graph for this function:

Here is the caller graph for this function:

void getStringBox ( char **  text,
double  textPos[2],
int  textDim[2],
BOOL  autoSize,
double  userSize[2],
double  angle,
int  fontId,
int  fontSize,
double  corners[4][2] 
)

compute the four corners of a text works only in 2D

Definition at line 36 of file StringBox.c.

References desallocateMatrix(), FALSE, getStringsPositions(), HDouble2Pixel, newCompleteMatrix(), NULL, pos, WDouble2Pixel, XDouble2Pixel, XDPixel2Double, YDouble2Pixel, and YDPixel2Double.

00045 {
00046   int pos[2] ;
00047   int textSize[2] = {0,0} ;
00048   int corn[4][2] ;
00049   StringMatrix * strings = newCompleteMatrix( (void **) text, textDim[0], textDim[1] ) ;
00050 
00051   /* take coordinates in pixels */
00052   pos[0] = XDouble2Pixel( textPos[0] ) ;
00053   pos[1] = YDouble2Pixel( textPos[1] ) ;
00054 
00055   if ( !autoSize )
00056   {
00057     textSize[0] = WDouble2Pixel( textPos[0], userSize[0] ) ;
00058     textSize[1] = HDouble2Pixel( textPos[1], userSize[1] ) ;
00059   }
00060 
00061   /* NULL because we don't need the position of each string */
00062   getStringsPositions( strings, &fontId, &fontSize, pos, autoSize, textSize, FALSE, angle, NULL, corn ) ;
00063 
00064   /* take everything back to user coordinates */
00065   /* to retrieve exactly the first corner as in stringl we take the input */
00066   corners[0][0] = XDPixel2Double( corn[0][0] ) ;
00067   corners[0][1] = YDPixel2Double( corn[0][1] ) ;
00068 
00069   corners[1][0] = XDPixel2Double( corn[1][0] ) ;
00070   corners[1][1] = YDPixel2Double( corn[1][1] ) ;
00071 
00072   corners[2][0] = XDPixel2Double( corn[2][0] ) ;
00073   corners[2][1] = YDPixel2Double( corn[2][1] ) ;
00074 
00075   corners[3][0] = XDPixel2Double( corn[3][0] ) ;
00076   corners[3][1] = YDPixel2Double( corn[3][1] ) ;
00077 
00078   /* we don't need the matrix anymore, but the text is needed */
00079   desallocateMatrix( strings ) ;
00080 
00081 }

Here is the call graph for this function:

int getStringHorizontalSpace ( void   ) 

returns the minimal space between too consecutive strings horizontally.

Definition at line 447 of file StringBox.c.

References getStringBbox(), and pos.

Referenced by getStringsRect().

00448 {
00449   int rect[4] ;
00450   int pos[2] = {0,0} ;
00451   /* return the width of a space */
00452   getStringBbox( " ", pos, rect ) ;
00453   return rect[2] ;
00454 }

Here is the call graph for this function:

Here is the caller graph for this function:

void getStringPositionTranslation ( BOOL  centeredPos,
int  textSize[2],
int  bbox[4][2],
int  trans[2] 
)

Get the translation which should be applied to the text depending on the meaning of its position.

Parameters:
centeredPos specify the meaning of the position of the text. If FALSE, the position corresponds to the position of the lower left point. So nothing needs to be changed. If TRUE, the center is the position corresponds to the center of the text bounding box and then a translation must be performed.
textSize width and height wanted for the text.
bbox The four corners of the computed boundign box of the text. The first corner should correspond to the position of the text.
trans Translation to apply to the text.

Definition at line 471 of file StringBox.c.

Referenced by getStringsPositions().

00472 {
00473   if ( centeredPos )
00474   {
00475     trans[0] = ( textSize[0] + bbox[0][0] - bbox[2][0] ) / 2 ;
00476     trans[1] = ( -textSize[1] + bbox[0][1] - bbox[2][1] ) / 2 ;
00477   }
00478   else
00479   {
00480     trans[0] = 0 ;
00481     trans[1] = 0 ;
00482   }
00483 }

Here is the caller graph for this function:

void getStringsPositions ( StringMatrix strMat,
int fontId,
int fontSize,
int  textPos[2],
BOOL  autoSize,
int  textSize[2],
BOOL  centerPos,
double  angle,
Vect2iMatrix stringPosition,
int  boundingBox[4][2] 
)

Compute an array of cells in which each string will fit. The bounding box of the finally displayed string is also computed. The generated array of cells can the be used for the display with the drawStringsInPosition routine.

Parameters:
strMat Set of string.
fontId specify the fontId of the strings.
fontSize if autoSize is on then specify the size of the strings. Otherwise, this returns the size which should be used to display the strings in the cell array.
textPos Position of the upper left point of the string array and center of rotation.
autoSize If TRUE, the size of the text is displayed usign the specified font. If flase the width and height of the text are specified by the user.
textSize if autoSize is false, specify the size of the rectangle in which the text must fit.
angle Angle for the rotation of the strings.
centerPos Specify where is the rotation center of the string. If TRUE in the middle of the array, otherwise in the bottom-left.
stringPosition matrix containing the corners of the cells. Element (i,j) of this matrix correspond to the upper-left point of the string (i,j). It size must be equal to the size of strMat plus one in each dimension. If NULL, not computed.
boundingBox position of the four corners of the bounding box surrounding the array of cells. The points are given clockwise.

Definition at line 218 of file StringBox.c.

References Abs, C2F, dr(), EPSILON, getStringPositionTranslation(), getStringsRect(), getStringsRectSized(), L, NULL, PD0, PI0, rotateBoundingBox(), rotateVect2iMatrix(), translateBoundingBox(), translateVect2iMatrix(), and v.

Referenced by drawTextEntity(), getStringBox(), and getTextBoundingBox().

00228 {
00229   integer curFont[2]  ;
00230   integer verbose = 0 ;
00231   integer v           ;
00232   int trans[2] ;
00233 
00234   if ( autoSize )
00235   {
00236     /* get the current font */
00237     /* we need to change the defaut font before using xstringl */
00238     C2F(dr)("xget","font",&verbose,curFont,&v,PI0,PI0,PI0,PD0,PD0,PD0,PD0,5L,5L);
00239 
00240     /* set the new font */
00241     C2F(dr)("xset","font",fontId,fontSize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00242 
00243     /* compute the stringPosition and bounding box in pixels without rotation */
00244     getStringsRect( strMat, textPos, stringPosition, boundingBox ) ;
00245 
00246     /* return to the previous font */
00247     C2F(dr)("xset","font",&curFont[0],&curFont[1],PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00248   }
00249   else
00250   {
00251     getStringsRectSized( strMat, textPos, stringPosition, boundingBox, textSize, fontSize ) ;
00252   }
00253 
00254   /* for now we have computes the matrix as if its position was corresponding to its */
00255   /* lower-left vertice. */
00256   /* we must now translate the points depending on where is really the center relatively */
00257   /* to the array. */
00258   getStringPositionTranslation( centerPos, textSize, boundingBox, trans ) ;
00259   if ( stringPosition != NULL )
00260   {
00261     translateVect2iMatrix( stringPosition, trans ) ;
00262   }
00263   translateBoundingBox( boundingBox, trans ) ;
00264 
00265   /* then turn everything, we need to turn them in pixels because of logarithmic scale */
00266   if ( Abs( angle ) > EPSILON )
00267   {
00268     if ( stringPosition != NULL )
00269     {
00270       rotateVect2iMatrix( stringPosition, textPos, angle ) ;
00271     }
00272     rotateBoundingBox( boundingBox, textPos, angle ) ;
00273   }
00274 
00275 }

Here is the call graph for this function:

Here is the caller graph for this function:

void getStringsRect ( StringMatrix strMat,
int  textPos[2],
Vect2iMatrix stringPosition,
int  boundingBox[4][2] 
)

Compute an array of cells in which a set of strings can be displayed. The size of the array is automatically computed using the current font. This routine does not compute any rotation.

Parameters:
strMat Set of strings.
textPos Position of the upper left point of the string array.
stringPosition matrix containing the corners of the cells. Element (i,j) of this matrix correspond to the upper-left point of the string (i,j). It size must be equal to the size of strMat plus one in each dimension. If NULL, not computed.
boundingBox position of the four corners of the bounding box surrounding the array of cells.

Definition at line 83 of file StringBox.c.

References copyVect2iMatElement(), FREE, getMatNbCol(), getMatNbRow(), getStringBbox(), getStringHorizontalSpace(), getStringVerticalSpace(), getStrMatElement(), i, j, MALLOC, Max, and NULL.

Referenced by getStringsPositions(), and getStringsRectSized().

00087 {
00088   /* the space size between two consecutive strings in a row */
00089   int hSpace = getStringHorizontalSpace() ;
00090   int vSpace = getStringVerticalSpace()   ;
00091   int * rowHeight ; /* vectors containing height and width of column of the array*/
00092   int * colWidth  ;
00093 
00094   int i ;
00095   int j ;
00096   int nbRow = getMatNbRow( strMat ) ;
00097   int nbCol = getMatNbCol( strMat ) ;
00098   int rect[4] ;
00099   int curHeight = 0 ; /* height in pixels of the current row */
00100   int curWidth  = 0 ; /* lenght of the longest row in pixels */
00101 
00102 
00103   /* initialize arrays */
00104   rowHeight = MALLOC( (nbRow + 1) * sizeof( int ) ) ;
00105   colWidth  = MALLOC( (nbCol + 1) * sizeof( int ) ) ;
00106 
00107   /* the tricky part */
00108 
00109   /* we first compute the width of each row  of the array */
00110   /* The width is given by the tallest string of each row */
00111 
00112   rowHeight[nbRow] = textPos[1] ;
00113 
00114   /* begin with the lower left string which is at position textPos */
00115   for ( i = nbRow - 1 ; i >= 0 ; i-- )
00116   {
00117     for ( j = 0 ; j < nbCol ; j++ )
00118     {
00119       getStringBbox( getStrMatElement( strMat, i, j ), textPos, rect ) ;
00120       curHeight = Max( curHeight, rect[3] ) ;
00121     }
00122     /* the height of the current column is the max of the height its tallest string + vSpace */
00123     rowHeight[i] = rowHeight[i+1] - curHeight - vSpace ;
00124     curHeight = 0 ;
00125   }
00126 
00127   /* same for columns */
00128   colWidth[0] = textPos[0] ;
00129 
00130   for ( j = 0 ; j < nbCol ; j++ )
00131   {
00132     for ( i = nbRow - 1 ; i >= 0 ; i-- )
00133     {
00134       getStringBbox( getStrMatElement( strMat, i, j ), textPos, rect ) ;
00135       curWidth = Max( curWidth, rect[2] ) ;
00136     }
00137     colWidth[j+1] = colWidth[j] + curWidth + hSpace ;
00138     curWidth = 0 ;
00139   }
00140 
00141   /* now fill the matrix */
00142   if ( stringPosition != NULL )
00143   {
00144     for ( i = 0 ; i <= nbRow ; i++ )
00145     {
00146       for ( j = 0 ; j <= nbCol ; j++ )
00147       {
00148         int intersect[2] = { colWidth[j], rowHeight[i] } ;
00149         copyVect2iMatElement( stringPosition, i, j, intersect ) ;
00150       }
00151     }
00152   }
00153 
00154   /* get the bounding box */
00155   boundingBox[0][0] = textPos[0] ;
00156   boundingBox[0][1] = textPos[1] ;
00157 
00158   boundingBox[1][0] = boundingBox[0][0] ;
00159   boundingBox[1][1] = rowHeight[0] ;
00160 
00161   boundingBox[2][0] = colWidth[nbCol] ;
00162   boundingBox[2][1] = boundingBox[1][1] ;
00163 
00164   boundingBox[3][0] = boundingBox[2][0] ;
00165   boundingBox[3][1] = boundingBox[0][1] ;
00166 
00167   FREE( rowHeight ) ;
00168   FREE( colWidth  ) ;
00169 
00170 }

Here is the call graph for this function:

Here is the caller graph for this function:

void getStringsRectSized ( StringMatrix strMat,
int  textPos[2],
Vect2iMatrix stringPosition,
int  boundingBox[4][2],
int  userSize[2],
int newFontSize 
)

Compute an array of cells in which a set of strings can be displayed when the size (width and height) of the array are specified by user. This routine does not compute any rotation.

Parameters:
strMat Set of strings.
textPos Position of the upper left point of the string array.
stringPosition matrix containing the corners of the cells. Element (i,j) of this matrix correspond to the upper-left point of the string (i,j). It size must be equal to the size of strMat plus one in each dimension. If NULL, not computed.
boundingBox position of the four corners of the bounding box surrounding the array of cells.
userSize width and height of the array of cells.
newFontSize font size which would fit the array best using the strings in strMat.

Definition at line 172 of file StringBox.c.

References C2F, computeSuitableFont(), dr(), getStringsRect(), homothVect2iMatrix(), iHomothety2D(), L, NULL, PD0, PI0, and v.

Referenced by getStringsPositions().

00178 {
00179   integer curFont[2]  ;
00180   integer verbose = 0 ;
00181   integer v           ;
00182   integer fontSizeOne = 1 ;
00183   double homothFactors[2] ;
00184 
00185   /* first get the automatic array with font 1 */
00186 
00187   /* get the current font */
00188   /* we need to change the defaut font before using xstringl */
00189   C2F(dr)("xget","font",&verbose,curFont,&v,PI0,PI0,PI0,PD0,PD0,PD0,PD0,5L,5L);
00190 
00191   /* set the new font */
00192   C2F(dr)("xset","font",&(curFont[0]),&fontSizeOne,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00193 
00194   /* get the displaying array */
00195   getStringsRect( strMat, textPos, stringPosition, boundingBox ) ;
00196 
00197   /* get the homothety factors */
00198   /* horizontal : userWidth / bbWidth */
00199   homothFactors[0] = ((double) userSize[0]) / ( boundingBox[2][0] - boundingBox[0][0] ) ;
00200   homothFactors[1] = ((double) userSize[1]) / ( boundingBox[0][1] - boundingBox[2][1] ) ;
00201 
00202   /* apply homothety on the matrix and boundingbox */
00203   iHomothety2D( boundingBox[1], boundingBox[0], homothFactors, boundingBox[1] ) ;
00204   iHomothety2D( boundingBox[2], boundingBox[0], homothFactors, boundingBox[2] ) ;
00205   iHomothety2D( boundingBox[3], boundingBox[0], homothFactors, boundingBox[3] ) ;
00206 
00207   /* we must tkae the min from both direction to avoid strings to go over the lines. */
00208   if ( stringPosition != NULL )
00209   {
00210     homothVect2iMatrix( stringPosition, boundingBox[0], homothFactors ) ;
00211     *newFontSize = computeSuitableFont( strMat, stringPosition ) ;
00212   }
00213 
00214   /* return to the previous font */
00215   C2F(dr)("xset","font",&curFont[0],&curFont[1],PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00216 }

Here is the call graph for this function:

Here is the caller graph for this function:

int getStringVerticalSpace ( void   ) 

returns the minimal space between too consecutive strings vertically.

Definition at line 439 of file StringBox.c.

References getStringBbox(), and pos.

Referenced by getStringsRect().

00440 {
00441   int rect[4] ;
00442   int pos[2] = {0,0} ;
00443   getStringBbox( " ", pos, rect ) ;
00444   return rect[3] ;
00445 }

Here is the call graph for this function:

Here is the caller graph for this function:

void getTextAabb ( sciPointObj pText,
int  rectPix[4],
int  cornPix[4][2] 
)

Compute the axis aligned bounding box of a text object.

Parameters:
pText Pointer on the object to surround.
rectPix Bounding box (x,y,w,h) in pixel coordinates. If NULL, not computed. (x,y) is the coordinates of the bottom left vertice.
conrPix The four corners of the real bounding box. If NULL, not computed.

Definition at line 382 of file StringBox.c.

References abs, getTextBoundingBox(), Max, Min, and NULL.

00385 {
00386   if ( cornPix == NULL )
00387   {
00388 
00389     getTextBoundingBox( pText, cornPix, NULL ) ;
00390 
00391     if ( rectPix != NULL )
00392     {
00393       rectPix[0] = Min( cornPix[0][0], Min( cornPix[1][0], Min( cornPix[2][0], cornPix[3][0] ) ) ) ;
00394       /* in pixel the bottom left point has the maximal y value */
00395       rectPix[1] = Max( cornPix[0][1], Max( cornPix[1][1], Max( cornPix[2][1], cornPix[3][1] ) ) ) ;
00396       rectPix[2] = Max( abs( cornPix[2][0] - cornPix[0][0] ), abs( cornPix[3][0] - cornPix[1][0] ) ) ;
00397       rectPix[3] = Max( abs( cornPix[2][1] - cornPix[0][1] ), abs( cornPix[3][1] - cornPix[1][1] ) ) ;
00398     }
00399   }
00400   else
00401   {
00402     getTextBoundingBox( pText, cornPix, NULL ) ;
00403 
00404     if ( rectPix != NULL )
00405     {
00406       rectPix[0] = Min( cornPix[0][0], Min( cornPix[1][0], Min( cornPix[2][0], cornPix[3][0] ) ) ) ;
00407       /* in pixel the bottom left point has the maximal y value */
00408       rectPix[1] = Max( cornPix[0][1], Max( cornPix[1][1], Max( cornPix[2][1], cornPix[3][1] ) ) ) ;
00409       rectPix[2] = Max( abs( cornPix[2][0] - cornPix[0][0] ), abs( cornPix[3][0] - cornPix[1][0] ) ) ;
00410       rectPix[3] = Max( abs( cornPix[2][1] - cornPix[0][1] ), abs( cornPix[3][1] - cornPix[1][1] ) ) ;
00411     }
00412   }
00413 
00414 }

Here is the call graph for this function:

void getTextBoundingBox ( sciPointObj pText,
int  cornPix[4][2],
double  corners[4][2] 
)

Compute the bounding box of a text object.

Parameters:
pText Pointer on the object to surround.
cornPix Bounding box in pixel coordinates. If NULL, not computed.
corners Bounding box in user coordinates. If NULL, not computed.

Definition at line 277 of file StringBox.c.

References DEG2RAD, getPixelCoordinates(), getStringsPositions(), NULL, PixelHeight2d(), PixelWidth2d(), pTEXT_FEATURE, sciGetAutoSize(), sciGetCenterPos(), sciGetFontDeciWidth(), sciGetFontOrientation(), sciGetFontStyle(), sciGetIs3d(), sciGetParentSubwin(), sciGetText(), sciGetUserSize(), updateScaleIfRequired(), sciText::x, XDouble2Pixel, XDPixel2Double, sciText::y, YDouble2Pixel, YDPixel2Double, and sciText::z.

Referenced by computeLabelAutoPos(), getTextAabb(), and sci_StringBox().

00280 {
00281   int           fontId   = sciGetFontStyle( pText ) ;
00282   int           fontSize = sciGetFontDeciWidth( pText ) / 100 ;
00283   double        angle    = DEG2RAD( sciGetFontOrientation (pText) / 10 ) ; 
00284   int           position[2] ;
00285   double        textPos[3]  ;
00286   double        userSize[2] ;
00287   int           textSize[2] ;
00288   sciText     * ppText   = pTEXT_FEATURE( pText ) ;
00289   sciPointObj * parentSW = sciGetParentSubwin( pText ) ;
00290 
00291   /* transform the position in pixels */
00292   /* we don't take the axes reverse into account. This has obviously no meaning for text.*/
00293   textPos[0] = ppText->x ;
00294   textPos[1] = ppText->y ;
00295   textPos[2] = ppText->z ;
00296 
00297   updateScaleIfRequired( parentSW ) ;
00298 
00299   if ( sciGetIs3d( pText ) )
00300   {
00301     /* normal case */
00302     getPixelCoordinates( parentSW, textPos, position ) ;
00303   }
00304   else
00305   {
00306     /* special for label, use of the 2d scale */
00307     position[0] = XDouble2Pixel( textPos[0] ) ;
00308     position[1] = YDouble2Pixel( textPos[1] ) ;
00309   }
00310 
00311   sciGetUserSize( pText, &(userSize[0]), &(userSize[1]) ) ;
00312 
00313   /* We take the size in 2d. */
00314   textSize[0] = PixelWidth2d(  parentSW, ppText->x, userSize[0] ) ;
00315   textSize[1] = PixelHeight2d( parentSW, ppText->y, userSize[1] ) ;
00316 
00317   if ( cornPix == NULL )
00318   {
00319     int corn[4][2] ;
00320     /* NULL because we don't need the position of each string */
00321     getStringsPositions( sciGetText( pText )     ,
00322       &fontId                 ,
00323       &fontSize               ,
00324       position                ,
00325       sciGetAutoSize( pText ) ,
00326       textSize                ,
00327       sciGetCenterPos( pText ),
00328       angle                   ,
00329       NULL                    ,
00330       corn                     ) ;
00331     if ( corners != NULL )
00332     {
00333       /* take everything back to user coordinates */
00334       /* to retrieve exactly the first corner as in stringl we take the input */
00335       corners[0][0] = XDPixel2Double( corn[0][0] ) ;
00336       corners[0][1] = YDPixel2Double( corn[0][1] ) ;
00337 
00338       corners[1][0] = XDPixel2Double( corn[1][0] ) ;
00339       corners[1][1] = YDPixel2Double( corn[1][1] ) ;
00340 
00341       corners[2][0] = XDPixel2Double( corn[2][0] ) ;
00342       corners[2][1] = YDPixel2Double( corn[2][1] ) ;
00343 
00344       corners[3][0] = XDPixel2Double( corn[3][0] ) ;
00345       corners[3][1] = YDPixel2Double( corn[3][1] ) ;
00346     }
00347   }
00348   else
00349   {
00350     /* NULL because we don't need the position of each string */
00351     getStringsPositions( sciGetText( pText )     ,
00352       &fontId                 ,
00353       &fontSize               ,
00354       position                ,
00355       sciGetAutoSize( pText ) ,
00356       textSize                ,
00357       sciGetCenterPos( pText ),
00358       angle                   ,
00359       NULL                    ,
00360       cornPix                  ) ;
00361 
00362     if ( corners != NULL )
00363     {
00364       /* take everything back to user coordinates */
00365       /* to retrieve exactly the first corner as in stringl we take the input */
00366       corners[0][0] = XDPixel2Double( cornPix[0][0] ) ;
00367       corners[0][1] = YDPixel2Double( cornPix[0][1] ) ;
00368 
00369       corners[1][0] = XDPixel2Double( cornPix[1][0] ) ;
00370       corners[1][1] = YDPixel2Double( cornPix[1][1] ) ;
00371 
00372       corners[2][0] = XDPixel2Double( cornPix[2][0] ) ;
00373       corners[2][1] = YDPixel2Double( cornPix[2][1] ) ;
00374 
00375       corners[3][0] = XDPixel2Double( cornPix[3][0] ) ;
00376       corners[3][1] = YDPixel2Double( cornPix[3][1] ) ;
00377     }
00378   }
00379 
00380 }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL isFittingInCell ( char *  string,
int  cellWidth,
int  cellHeight 
)

Check if a string can be displayed in a cell with a certain width and height.

Definition at line 456 of file StringBox.c.

References FALSE, getStringBbox(), pos, and TRUE.

Referenced by computeSuitableFont().

00457 {
00458   int rect[4] ;
00459   int pos[2] = {0,0} ;
00460 
00461   /* get the size of the string */
00462   getStringBbox( string, pos, rect ) ;
00463 
00464   if ( rect[2] < cellWidth && rect[3] < cellHeight )
00465   {
00466     return TRUE ;
00467   }
00468   return FALSE ;
00469 }

Here is the call graph for this function:

Here is the caller graph for this function:

void rotateBoundingBox ( int  boundingBox[4][2],
int  center[2],
double  angle 
)

Rotate four points around the first one.

Parameters:
boundingBox the four 2D points.
angle rotation angle in radian.

Definition at line 417 of file StringBox.c.

References Abs, EPSILON, and iRotate2Dim().

Referenced by drawTextEntity(), and getStringsPositions().

00418 {
00419   if ( Abs( angle ) > EPSILON )
00420   {
00421     double cosAngle = cos( angle ) ;
00422     double sinAngle = sin( angle ) ;
00423     iRotate2Dim( boundingBox[0], center, cosAngle, sinAngle, boundingBox[0] ) ;
00424     iRotate2Dim( boundingBox[1], center, cosAngle, sinAngle, boundingBox[1] ) ;
00425     iRotate2Dim( boundingBox[2], center, cosAngle, sinAngle, boundingBox[2] ) ;
00426     iRotate2Dim( boundingBox[3], center, cosAngle, sinAngle, boundingBox[3] ) ;
00427   }
00428 }

Here is the call graph for this function:

Here is the caller graph for this function:

void translateBoundingBox ( int  boundingBox[4][2],
int  trans[2] 
)

Translae four points around the first one.

Parameters:
boundingBox the four 2D points.
angle rotation angle in radian.

Definition at line 430 of file StringBox.c.

References iTranslate2D().

Referenced by getStringsPositions().

00431 {
00432   iTranslate2D( boundingBox[0], trans, boundingBox[0] ) ;
00433   iTranslate2D( boundingBox[1], trans, boundingBox[1] ) ;
00434   iTranslate2D( boundingBox[2], trans, boundingBox[2] ) ;
00435   iTranslate2D( boundingBox[3], trans, boundingBox[3] ) ;
00436 
00437 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sun Mar 4 15:54:57 2007 for Scilab [trunk] by  doxygen 1.5.1