Community
DWF
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DWFToolkit Text Heights

16 REPLIES 16
Reply
Message 1 of 17
GBGB1360
1597 Views, 16 Replies

DWFToolkit Text Heights

Hello,

 

I need help with text heights.

 

1. The texts in my DWF file are of the same height (31 units in AutoCAD), but when  I read them with the DWF Toolkit using font.height().height(), I am getting varying values. Why is this so, or am I getting text heights the wrong way?

I tried to use WT_Text::bounds() to get the bounding box of the text and from there get the height, but I get a compiler error that bounds() is a protected method whereas the documentation lists it as a public function.

2. I need to scale the text heights to paper units. At the moment, I am using the same scale that I use for scaling coordinates but this doesn't seem to be right. How can I scale text heights correctly?

 

Thanks for sny help.

 

Gabriel

 

16 REPLIES 16
Message 2 of 17
GBGB1360
in reply to: GBGB1360

I carried out further test on this by looking at an ASCII output of the DW. I found out that font nodes without a Height attribute are given a (wrong) height value (of 1000 in this case). Below is part of the DWF ASCII output

 

(Font (Height 385))
   (Text -3923,-13712 'FOR ILLUSTRATIVE PURPOSES ONLY - NOT TO SCALE')
(FontExtension 'Arial' 'Arial')
(Font (Style))
   (Text -6521,-14231 'The position & size of doors..')
(Font (Height 462))
   (Text -5590,-14751 "00A9")
(Font (Height 385))
   (Text -5249,-14751 'Unauthorised reproduction prohibited.')
(Layer 2 )
(Font (Height 339))

 

In the above, the text 'The position & size of doors' is given a height of 1000 because there is not Height in the Font specification before it (just a Style).

Is 1000 always used as font height in this type of case, or is there a function that can tell that the value of the height is not valid? I need to know what the correct height is for evety piece of text in the DWF.

 

Thanks

 

Gabriel

Message 3 of 17
SilviaCao
in reply to: GBGB1360

Thank you for your questions.

 

I will answer them one question at a time.

 

1. You are right to get text height by using font.height().height(); the height value is in drawing units  If the height is not correct, please make sure you get the right font at first.

2. WT_Text::bounds() is a publish function, you can use WT_Text::bounds()::bounds() to get the text bounds.

3.  Scale text height: paperHeight = font.height().height() * logicaltoPaper * units;

logicaltoPaper = 100000;

units = 1 (inch)

units = 25.4 (mm)

……

4. Style is used for other font option (bold, italic or underlined), in this case, the font is with the default height (1000) when no height has been set.

 

Please reply back if you have any further questions.

ADR/DWF Customer Support



Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 4 of 17
GBGB1360
in reply to: SilviaCao

Hi Silvia,

 

Thanks for your help.

Is "logicaltoPaper" always 100000?

 

Gabriel

Message 5 of 17
SilviaCao
in reply to: GBGB1360

Yes, “logicaltoPaper” is always 100000.

 

 Correct my mistake:

 paperHeight = font.height().height() /( logicaltoPaper * units)

 

 Silvia

 ADR/DWF Customer Support



Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 6 of 17
GBGB1360
in reply to: SilviaCao

Hi Silvia,

 

I don't think this working for me. Below is what I have:

 DWF units is in mm and font height is 620 (from the DWF Tookit). I plotted the DWF in mm.

That would mean:

 

Paper height = 620 / (25.4 * 100000)

=0.000244 (mm?)

 

In AutoCAD, the text height is 58.4. The drawing unit is inches, so I assume this is 58.4 inches (i.e. 1483.4mm).

 

Could you please help reconcile these values.

 

Thanks a lot

 

Gabriel

 

Message 7 of 17
SilviaCao
in reply to: GBGB1360

The function (paperHeight = font.height().height() / ( logicaltoPaper * units) ) is correct to get the common text height; so please send us more information to research:

 

  1. Make sure you get the font height 620 by using DWF Toolkit function font.height().height(), which is different from the value that stores in DWF file; DWF Toolkit has transformed the value.
  2. Does the text group in a viewport? If yes, the font height should apply the viewport transform matrix.
  3. Please attach the test DWF and a snapshot with the highlight case text to this thread.

 

Silvia

ADR/DWF Customer Support



Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 8 of 17
GBGB1360
in reply to: SilviaCao

Hi Silvia,

 

Thanks for looking at this again. Below is a sample output snippet showing the text attrubutes in the DWF. It is from the DWF Toolkit. The text is "Ground Floor" and, as you can see, it's height is 605. In AutoCAD, the text height is 58.4160 (inches)

(Layer 2 Text)
(FontExtension 'Arial' 'Arial Bold')
(Font (Charset ANSI) (Family swiss) (Style bold) (Height 605) (Rotation 65535))
   (Text -3032,-1943 'Ground Floor')
(Layer 1 )
   P 4 2098,4672 1016,4672 1016,4635 2098,4635
   L 2210,4635 2210,5265

I am attaching the DWG, DWF (binary & text) in case these would shed more light.

 

Thanks again.

 

Gabriel

Message 9 of 17
SilviaCao
in reply to: GBGB1360

Thank you for your feedback.

 

A DWF file can have the following elements:

  1. W2d coordinates (Wc)
  2. Graphic matrix (Gm)
  3. Viewport matrix (Vm)
  4. Units

 

General we can get the model coordinates (Mc):

  1. The w2d point is not in any viewport

Mc ≈ Wc * Gm;

  1. The w2d point is in a viewport

Mc ≈ Wc * Vm;

 

Then apply the units to the model coordinates we can get the real coordinates.

 

In the “Test3.dwf”:

The text font height is 605, but not the text height; so firstly it needs to get the text bounding box in a Device Content with the text font; then we can get the text height (Th) from the bounding box.

 

And then apply the Viewport matrix (Vm) = (7.4150283773999996 -4.5402454324000004e-016 0 0

4.5405322039999997e-016  7. 4154967263999998 0 0

0 0 54.986118658772803 0

   -15923491465.474878 -130554.74304523563 0 54.986118658772803)

To the Th, and get the Model length (Ml) ≈ Th * Vm;

 

The “Test3.dwf” does not contain the units.



Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 10 of 17
GBGB1360
in reply to: SilviaCao

Hi Sylvia,

 

Thanks for getting back on this. Unfortunately, I don't understand your explanation about getting the text height. Could you explain the stages of the transformation and what the result of each stage is. Also, I don't understand the matrix you referred to.

 

Thanks for your help.

 

Gabriel

Message 11 of 17
SilviaCao
in reply to: GBGB1360

1.Use the DWF Toolkit to extract the DWF file. There are three objects about the text height:

   WT_Viewport

   WT_Font

   WT_Text

 

2.Get the Viewport units, which contains the viewport transform matrix:

   WT_Viewport:: viewport_units().application_to_dwf_transform().elements()

 

3.Create a Device Context (HDC);

   Create a HFONT from WT_Font;

   Draw the WT_Text string in the DC;

   Calculate the text height in the DC.

 

4.Apply the viewport matrix to the text height.



Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 12 of 17
GBGB1360
in reply to: SilviaCao

Hi Sylvia,

 

Thanks a lot for the explanation.

 

After going through the steps, I am observing that the final height is the same as the height given by WT_Font.height();

 

Regards,

 

Gabriel

Message 13 of 17
SilviaCao
in reply to: GBGB1360

If the final height is the bounding box height of the “Ground Floor”, the value should be correct (the value depends on the device context the “Ground Floor” draws on):

 

605 * viewport scale (7.4150283773999996/ 54.986118658772803) ≈ 81.6;

Autodesk Design Review (ADR) gets the height of 620, and attaches the “Test3.jpg” of the final bounding box height of “Ground Floor”.

 

The bounding box is bigger than each character height; so the next step is to get the more exact height of each character.

 

If the final height is the height of character “G”, please attach a snap of code to this thread.

 

More:

The following steps are to get the bounding box of “Ground Floor” in ADR:

  1. Open the Test3.dwf in ADR;
  2. Press “Ctrl+F”, and pop up the “Find” panel in ADR;
  3. Input “Ground” in “Find” panel and search the text;
  4. ADR will find a result in the result panel;
  5. Click the result, ADR will highlight the bounding box of “Ground Floor” in the canvas;
  6. Measure the height of bounding box.


Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 14 of 17
GBGB1360
in reply to: SilviaCao

Hi Sylvia,

 

I am somewhat confused now after reading your latest notes.

The relevant parts of my code are in the attached text file.

Some explanation on the logic:

Creation and release of the device handle (HDC) are not shown in the code snippet.

I am creating the Window Font (HFONT) in the set_font_action() callback

The creation of the text takes place in the set_text_action() callback. In this function sz.cy is 605, which is the value of font.height(), so I wonder if there is any need for all the calculations with the Windows API.

The viewport  transformation matrix elements are shown inside the function.

long textHeight = sz.cy / SCALEY gives me 81.6, which is also what you got.

 

 

Now, when I measure "Ground Floor" in ADR, I get the height of "G" to be 61 and the height of the bounding box to be 91. Since "G" is the biggest character in the text, I would expect the text height to be taken as the height of "G".

So, where are we (both you and I) getting 81.6? Either 61 or 91 would have made more sense to me as the text height.

 

It looks as if the scaling factor used in the transformation of texts from DWG to DWF is not the same factor used in transforming graphics (lines, etc.)

 

By the way, I am using the RECT values shown in the code because I don't know what else to use. I don't think it makes any difference however. Or does it?

 

Thanks for your help.

 

Gabriel

 

 

Message 15 of 17
SilviaCao
in reply to: GBGB1360

  1. The bounds of “G” is not same to the “Ground Floor”, so please test the GetTextExtentPoint32 with the section parameter “G” in the callback function agr_process_text;
  2. The CreateFont needs information from WT_Font which in the callback function agr_process_font.


Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 16 of 17
GBGB1360
in reply to: SilviaCao

I am still getting 605 for the size of "G".

Using   GetTextExtentPoint32(hDC,_T("G"),textLength,&sz) gives me sz.cy to be 605.

 

Thanks

 

Gabriel

Message 17 of 17
SilviaCao
in reply to: GBGB1360

Please try to disperse the character “G” to curves by function GetGlyphOutline; and then calculate the bounding box of the curves, which is also the bounding box of “G”.



Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost

 

”Tips

 

”Services