haplokuon / netDxf

.net dxf Reader-Writer
MIT License
981 stars 400 forks source link

Ask Help For Text/Mtext total length. #402

Open airsxue opened 2 years ago

airsxue commented 2 years ago

Hello, Thanks for your hard work for netDxf,I just want to know how can I get the total Length of a text or Mtext(as below pic. )? Thanks! image

airsxue commented 2 years ago

Hello, Thanks for your hard work for netDxf,I just want to know how can I get the total Length of a text or Mtext(as below pic. )? Thanks! image

BTW, I used tried to get the total Length by the "total Char count"* "width factor", but the result sstill has deviation with actual length.

airsxue commented 2 years ago

Hello, Thanks for your hard work for netDxf,I just want to know how can I get the total Length of a text or Mtext(as below pic. )? Thanks! image

sorry, correct the method i used tried, it should be "total Char count" "width factor" textHeight

Snailya commented 2 years ago

As far as I know, the length of the text is depends on the system's graphic render. So there's no method to get the text length before render. In windows, you can do this by gdi or gidplus. see https://stackoverflow.com/questions/263614/calculate-the-display-width-of-a-string-in-c

airsxue commented 2 years ago

As far as I know, the length of the text is depends on the system's graphic render. So there's no method to get the text length before render. In windows, you can do this by gdi or gidplus. see https://stackoverflow.com/questions/263614/calculate-the-display-width-of-a-string-in-c

Got it with many thanks

haplokuon commented 2 years ago

Both SHX and TTF fonts stores vector data information from which you can, from every single character (glyph), build words, sentences, paragraphs,... and get its measurements; but you will need to use other libraries for that. So, it is not true that the length of the text depends on the system graphic render, although it is common in them to find some kind getLength method.

airsxue commented 1 year ago

Both SHX and TTF fonts stores vector data information from which you can, from every single character (glyph), build words, sentences, paragraphs,... and get its measurements; but you will need to use other libraries for that. So, it is not true that the length of the text depends on the system graphic render, although it is common in them to find some kind getLength method.

so may i have your suggestion on which libraires can i use to measure the length of text? thanks