Code sample Home

Create texts with various alignment

void DemoTextAlign (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock, hEnt;
  int    EntType;
  COLORREF Color;
  double RectW = 500.0;
  double RectH = 50.0;
  double StepY = 60.0;
  double Htxt = 15.0;     // text height
  double WScale = 1.0;    // text width scale
  double X, Y, dx, dy;
 
  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );
  // Create rectangles and insert text at center point, changing alignment
  X = 0;
  Y = 0;
  lcBlockAddText2( hBlock, L"LC_TA_LEFBOT", X, Y, LC_TA_LEFBOT , Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  Y += StepY;
  lcBlockAddText2( hBlock, L"LC_TA_CENBOT", X, Y, LC_TA_CENBOT, Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  Y += StepY;
  lcBlockAddText2( hBlock, L"LC_TA_RIGBOT", X, Y, LC_TA_RIGBOT, Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  Y += StepY;
  lcBlockAddText2( hBlock, L"LC_TA_LEFCEN", X, Y, LC_TA_LEFCEN, Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  Y += StepY;
  lcBlockAddText2( hBlock, L"LC_TA_CENTER", X, Y, LC_TA_CENTER , Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  Y += StepY;
  lcBlockAddText2( hBlock, L"LC_TA_RIGCEN", X, Y, LC_TA_RIGCEN, Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  Y += StepY;
  lcBlockAddText2( hBlock, L"LC_TA_LEFTOP", X, Y, LC_TA_LEFTOP, Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  Y += StepY;
  lcBlockAddText2( hBlock, L"LC_TA_CENTOP", X, Y, LC_TA_CENTOP, Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  Y += StepY;
  lcBlockAddText2( hBlock, L"LC_TA_RIGTOP", X, Y, LC_TA_RIGTOP, Htxt, WScale, 0, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X, Y );
  dx = RectW * 0.35;
  dy = RectH * 0.3;
  Y = -StepY;
  lcBlockAddText3( hBlock, L"LC_TA_FIT", X-dx, Y-dy, X+dx, Y-dy, LC_TA_FIT, Htxt, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X-dx, Y-dy );
  lcBlockAddPoint( hBlock, X+dx, Y-dy );
  Y -= StepY;
  lcBlockAddText3( hBlock, L"LC_TA_ALIGNED", X-dx, Y-dy, X+dx, Y-dy, LC_TA_ALIGNED, WScale, 0 );
  lcBlockAddRect( hBlock, X, Y, RectW, RectH, 0, 0);
  lcBlockAddPoint( hBlock, X-dx, Y-dy );
  lcBlockAddPoint( hBlock, X+dx, Y-dy );

  // set red color for all text entities
  Color = RGB(255,0,0);
  hEnt = lcBlockGetFirstEnt( hBlock );
  while( hEnt ){
    EntType = lcPropGetInt( hEnt, LC_PROP_ENT_TYPE );
    if (EntType == LC_ENT_TEXT){
      lcPropPutInt( hEnt, LC_PROP_ENT_COLOR, Color );
    }
    hEnt = lcBlockGetNextEnt( hBlock, hEnt );
  }

  lcBlockUpdate( hBlock, false, 0 );
  // zoom extents
  lcWndZoomRect( hLcWnd, 0,0,0,0 );
  // and slightly reduce the view
  lcWndZoomScale( hLcWnd, 0.8 );
}
This will create a drawing as shown on the picture below:



Used functions:

lcBlockAddText2
lcBlockAddRect
lcBlockAddPoint

lcBlockGetFirstEnt
lcBlockGetNextEnt

lcBlockUpdate

lcWndZoomRect
lcWndZoomScale

lcPropGetHandle
lcPropGetInt
lcPropPutInt