More control on TextCell

Hello expert
I noticed three difficulties when using textcells with Diagram Studio. I hope you can help me with that:

  1. When changing the angle of textCell(example: TextCells[0]:=90), the textcell[0] jumps to an indesirable location inside the hosting block. I wish the "left" and "top" propereties of the textCell remain the same.

  2. When trying to flip a block horizontally for example, the textcells inside this block do not move at all
    (myBlock.HorizontalFlip:=not myBlock.HorizontalFlip)

3.Is it possible to calculate the width of the text (only the text) inside textcells[0] in term of relative values inside the block? I find this important to position the textcell[0] accuratly inside the host diagramblock

I thank you in advance for any ideas!

  1. That's by design. The rotation center of text cells belonging to a diagram block is the block center, not the text cell center. So the text cell will be rotated as if the whole block is rotated.

  2. HorizontalFlip is not completely implemented. Since font in text cell is not flipped, we decided not to touch text cell flipping yet.

  3. There is a protected method named CalculateTextRect that you might try to use to accomplish that. You will have to use a type hack to access the protected method.

for the third issue i tried to calulate TextRect as you suggested inside the methode:
DrawBlock(AInfo: TDiagramDrawInfo;ABlockInfo: TDiagramDrawBlockInfo);

sq:=TBlockHack(Self).CalculateTextRect(AInfo.DgrDrawer.Canvas,
,TextCells[0].Font,TextCells[0].BoundsRect,TextCells[0].text,TAlignment.taLeftJustify,TVertAlign.vaTop,false,0,0,0,true);

AInfo.DgrDrawer.Canvas is not accepted requiering Tcanvas not DgrCanvas...
How can I define canvas:Tcanvas?????

Sorry, since you are using the TDgrCanvas, you can use the function

    function InternalWriteTextDgr(ADrawer: TDgrBlockDrawer; AFont: TFont;
      ARect: TSquare; const S: string; HAlign: TAlignment;
      VAlign: TVertAlign; AWrap: boolean; AAngle: double; RotC: TDot;
      AClip, ADrawFrame, ADrawText: boolean; ATransparency: integer;
      AFrameMargin: integer=0): TSquare;

Set the parameter ADrawText to False so it will not effectively draw the cell, but just calculate the rect.

I tried the code you suggested. The square returned is more than twice bigger than the square realy surronding the text. The figure attached shows the two square obtained by the function!

I believe the function from Direct2dClasses: function TD2DCanvas.StringBounds(...) causes the error throught "txtLayout.GetMetrics(txtMetrics)"
It would be very nice if a such issue is fixed!!!
45

Is your diagram zoomed out or in (i.e., different than 100%)?

It is correct. Without zooming the Square fits exactly the surrounding area. Thought I would prefere the text to zoom as the surrounding Square. HowEver, since I understand now what happens, Iam able to make the correction by code.
Thank you again and again!

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.