Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextEntity need add AdjustAlignment function #535

Open
sungaoyong opened this issue Jan 17, 2025 · 2 comments
Open

TextEntity need add AdjustAlignment function #535

sungaoyong opened this issue Jan 17, 2025 · 2 comments

Comments

@sungaoyong
Copy link

Hello, I used your library to do a transfer of cad documents, the library is very powerful, to solve my needs, but there is a shortcoming to be improved.
My job involves output TextEntity, in which I set up InsertPoint, AlignmentPoint, and alignments such as HorizontalAlignment and VerticalAlignment.
But in fact this involves to recalculate InsertPoint position, for example, I if the horizontal is TextHorizontalAlignment Middle, so is need according to the text AlignmentPoint and output width, Subtract half the width of InsertPoint from the text output width, otherwise the dwg output will display incorrect loading. After loading, the position will be adjusted according to the alignment mode only after the corresponding attribute is refreshed in autocad. Now I write a method separately and add TextEntity for position calculation. I hope this AdjustAlignment function can also be added in TextEntity of this library. It will calculate the output width and alignment method according to the output value. Align the InsertPoint with the AlignmentPoint
I am now calculating that the font output width is the ttf display width calculated using the font of gdi, which may be incorrect for the built-in shx font.

Font font = new Font(" Song typeface ", dHeight);
SizeF size = g.MeasureString(strText, font);
return Math.Truncate(size.Width);

AdjustAlignment function adjusts the position of InsertPoint according to the alignment method

@DJGosnell
Copy link
Contributor

DJGosnell commented Jan 17, 2025

I have done a LOT of work with this and to calculate the points, it requires a full text rendering library (like WPF or SKIA for example) to accurately calculate these points as requested. This library does not have those dependencies and I think that if it did, it would quickly bloat the requirements of the library.

My opinion is that this should be the library consumer's job to get these points calculated as it will explode the scope of this project as text rendering is a deep rabbithole and that's even ignoring the whole AutoCAD SHX fonts which have their own independent set of rules.

@DomCR
Copy link
Owner

DomCR commented Jan 20, 2025

Hi @sungaoyong,

As @DJGosnell, this may add a lot of dependencies and it will defeat the purpose of a lightweight library focused on dxf and dwg.

I might need to take a look at this issue but in this extension project ACadSharp.Pdf so I can render the text correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants