Repository navigation
Conversation
…rs (#506) The height of a DXF TEXT or MTEXT (group 40) is the height of the capital letters, which AutoCAD and other viewers scale the font to, while Text.TextSize is the em height of the font. Since the move to ACadSharp the exporter wrote TextSize unchanged, so every other program showed exported texts 1.4 (Arial) to 1.6 (Consolas) times larger than CADability drew them and than their bounding cube. The netDxf exporter of 1.0.x had scaled the height by the font metrics. The export now multiplies TextSize by the cap height of the font, measured at the outline of "H" (FontCache.GetCapHeight, Text.CapHeightFactor), and the import divides by the same factor, so a round trip keeps TextSize and the extent unchanged. Imported DXF and DWG texts are therefore drawn larger than before, as large as AutoCAD shows them. The MTEXT line spacing is converted with the same factor. The export also writes the width factor (group 41) from the length of the line direction, which it dropped before, while the import already read it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F53kFpUYJXo4cE8wSe2jHi
DIMTXT, the text height of a DXF dimension style, is the height of the capital letters like the height of a TEXT, while CADability draws the dimension text with DimensionStyle.TextSize as the em height of the font. The export now multiplies TextSize by the cap height of the style's font and the import divides by it, so imported dimensions show their text as large as AutoCAD does and a round trip keeps TextSize. TextSizeTol follows TextSize, and TextDist is computed from the converted size, which keeps the distance of the text from the dimension line at DIMGAP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F53kFpUYJXo4cE8wSe2jHi
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #506.
Problem
Text.TextSizeandDimensionStyle.TextSizeare the em height of the font: CADability draws the glyphs with it, andText.GetBoundingCube()is computed from it. In DXF, the height of a TEXT or MTEXT (group 40) and the dimension text heightDIMTXTare the height of the capital letters, and AutoCAD and other viewers scale the font to that height.Since the move to ACadSharp (v1.1.0), the exporter wrote
TextSizeunchanged as the DXF height, and the importer read it back unchanged. So every other program showed exported texts larger than CADability draws them and larger than their bounding cube, by em height / cap height: 2048/1467 ≈ 1.40 for Arial and ≈ 1.6 for Consolas. The screenshot in the issue shows exactly these factors. Round trips through CADability were unaffected, which hid the bug. The netDxf exporter of 1.0.x had scaled the height by the font metrics (TextSize * 1000 / font.Height).Changes
FontCache.GetCapHeight/Text.CapHeightFactor/Text.GetCapHeightFactor(allinternal) give the cap height of a font as a fraction of its em height. It is measured at the outline of "H", so it works the same with the managed and the GDI font provider. If there is no font or no "H", the factor is 1.0.TextSize × cap height. The import divides by the same factor.DIMTXTis written asTextSize × cap heightof the style's font, and read back the other way.TextSizeTolfollowsTextSize.TextDistis computed from the converted size, so the distance of the text from the dimension line stays atDIMGAP × DIMSCALE.Texts in dimension blocks, dimensions drawn by ACadSharp, table cells and TOLERANCE entities all go through the TEXT import and are covered by the first point.
Behaviour change (for the release notes)
Imported DXF/DWG texts and dimension texts are now drawn larger in CADability than before, as large as AutoCAD shows them, about 1.4× for Arial. After an import,
TextSizeno longer equals the DXF height. Exporting and importing again keepsTextSize, the line spacing and the extent unchanged. No public API changes and no binary break, so a patch release.Tests
DxfTextHeightTest:DxfDimensionTest: four assertions that expectedTextSize == DIMTXTnow check that the capital letters are as high asDIMTXT. The existing import/export/import test still checks thatTextSizeis kept.CADability.ImportTests: 96 passed, 1 skippedCADability.Tests: 708 passed, 16 skippedCADability.Formsbuilds.Generated by Claude Code