This is an automated email from the ASF dual-hosted git repository. leginee pushed a commit to branch bugfix-dxf-filter in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 8063bc29835b4b249838d5ce5134e39c20fad074 Author: Peter Kovacs <[email protected]> AuthorDate: Sun Jul 5 15:34:25 2026 +0200 the file detector now ignores comments at the start of the file to identifiy DXF files. On import we tollerate now 1.0 as 1. Before it broke the read Measuring the arc's swept extent, not the full circle, so large-radius arcs don't blow up the scaling box ond collapse the drawing. --- main/filter/source/graphicfilter/idxf/dxfgrprd.cxx | 14 ++++++++++- main/filter/source/graphicfilter/idxf/dxfreprd.cxx | 24 +++++++++++++++---- main/svtools/source/filter/filter.cxx | 28 ++++++++++++++++++++-- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/main/filter/source/graphicfilter/idxf/dxfgrprd.cxx b/main/filter/source/graphicfilter/idxf/dxfgrprd.cxx index 57d362a33c..895469ece9 100644 --- a/main/filter/source/graphicfilter/idxf/dxfgrprd.cxx +++ b/main/filter/source/graphicfilter/idxf/dxfgrprd.cxx @@ -151,7 +151,7 @@ sal_uInt16 DXFGroupReader::Read() else if (nG< 140) ReadS( aTmp ); else if (nG< 148) F140_147[nG-140]=ReadF(); else if (nG< 170) ReadS( aTmp ); - else if (nG< 176) I170_175[nG-175]=ReadI(); + else if (nG< 176) I170_175[nG-170]=ReadI(); else if (nG< 180) ReadI(); else if (nG< 210) ReadS( aTmp ); else if (nG< 240) F210_239[nG-210]=ReadF(); @@ -330,6 +330,18 @@ long DXFGroupReader::ReadI() } while (*p==0x20) p++; + + // Tolerate an integer group value written in floating-point notation + // (e.g. "1.0"): some CAD applications (Pro/ENGINEER) emit integer group + // codes — such as the DIMSTYLE flags 71/72 — that way. Skip a trailing + // decimal fraction and keep the integer part; AutoCAD accepts this, whereas + // a strict reject aborts the whole import (issue 122565). + if (*p=='.') { + p++; + while (*p>='0' && *p<='9') p++; + while (*p==0x20) p++; + } + if (*p!=0) { bStatus=sal_False; return 0; diff --git a/main/filter/source/graphicfilter/idxf/dxfreprd.cxx b/main/filter/source/graphicfilter/idxf/dxfreprd.cxx index 6bcb2d49fd..9fee186bca 100644 --- a/main/filter/source/graphicfilter/idxf/dxfreprd.cxx +++ b/main/filter/source/graphicfilter/idxf/dxfreprd.cxx @@ -337,10 +337,26 @@ void DXFRepresentation::CalcBoundingBox(const DXFEntities & rEntities, } case DXF_ARC: { const DXFArcEntity * pE = (DXFArcEntity*)pBE; - DXFVector aC; - aE2W.Transform(pE->aP0, aC); - DXFVector aP=aC; aP.fx-=pE->fRadius; aP.fy-=pE->fRadius; rBox.Union(aP); - aP=aC; aP.fx+=pE->fRadius; aP.fy+=pE->fRadius; rBox.Union(aP); + // Measure the arc's SWEPT extent, not its full circle. A + // large-radius arc (nearly straight, common in CAD) has its + // centre far outside the drawing; unioning centre +/- radius + // blew the box up enormously and collapsed the real geometry + // (issue 122565). Sample along the sweep exactly as the renderer + // does (CCW from fStart by fdA, normalised to (0,360]) and map + // each point through the same ECS->WCS transform. + double fA1 = pE->fStart; + double fdA = pE->fEnd - fA1; + while (fdA>=360.0) fdA-=360.0; + while (fdA<=0.0) fdA+=360.0; + sal_uInt16 nSeg = (sal_uInt16)(fdA/4.0 + 0.5); + if (nSeg<1) nSeg=1; + for (sal_uInt16 nA=0; nA<=nSeg; nA++) { + double fAng = 3.14159265359/180.0 * + (fA1 + fdA*(double)nA/(double)nSeg); + UnionOCS(rBox, aE2W, pE->aP0 + + DXFVector(pE->fRadius*cos(fAng), + pE->fRadius*sin(fAng), 0.0)); + } break; } case DXF_TRACE: { diff --git a/main/svtools/source/filter/filter.cxx b/main/svtools/source/filter/filter.cxx index 6558b7cf38..bf1ed23db0 100644 --- a/main/svtools/source/filter/filter.cxx +++ b/main/svtools/source/filter/filter.cxx @@ -514,8 +514,32 @@ static sal_Bool ImpPeekGraphicFormat( SvStream& rStream, String& rFormatExtensio bSomethingTested=sal_True; i=0; - while (i<256 && sFirstBytes[i]<=32) - i++; + + // A DXF file may begin with one or more 999 comment groups (each is a + // "999" code line followed by a comment value line), e.g. files written + // by Pro/ENGINEER. Skip them before looking for the first real group, + // otherwise such valid DXF files are rejected as an unknown format + // (issue 122565). + for (;;) + { + while (i<256 && sFirstBytes[i]<=32) + i++; + if ( i+3<256 && sFirstBytes[i]=='9' && sFirstBytes[i+1]=='9' && + sFirstBytes[i+2]=='9' && sFirstBytes[i+3]<=32 ) + { + // skip the "999" code line and the comment value line after it + int nLine; + for ( nLine=0; nLine<2 && i<256; nLine++ ) + { + while (i<256 && sFirstBytes[i]!='\n' && sFirstBytes[i]!='\r') + i++; + while (i<256 && (sFirstBytes[i]=='\n' || sFirstBytes[i]=='\r')) + i++; + } + continue; + } + break; + } if (i<256) {
