diff --git a/sources/bordertitleblock.cpp b/sources/bordertitleblock.cpp index b1000ff09..6363c176b 100644 --- a/sources/bordertitleblock.cpp +++ b/sources/bordertitleblock.cpp @@ -673,7 +673,8 @@ void BorderTitleBlock::drawDxf( 1, 2, xCoord+recWidth/2, - color, + 1, + color, 0); }else{ Createdxf::drawTextAligned(file_path, @@ -686,7 +687,8 @@ void BorderTitleBlock::drawDxf( 1, 2, xCoord+recWidth/2, - color, + 1, + color, 0); } } @@ -721,7 +723,8 @@ void BorderTitleBlock::drawDxf( 1, 2, xCoord+recWidth/2, - color, + 1, + color, 0); row_string = incrementLetters(row_string); } diff --git a/sources/createdxf.cpp b/sources/createdxf.cpp index 861cf77c1..8811f13eb 100644 --- a/sources/createdxf.cpp +++ b/sources/createdxf.cpp @@ -744,7 +744,7 @@ void Createdxf::drawText(const QString& fileName, const QString& text,double x, /* draw aligned text in DXF Format */ // leftAlign flag added. If the alignment requested is 'fit to width' and the text length is very small, // then the text is either centered or left-aligned, depnding on the value of leftAlign. -void Createdxf::drawTextAligned(const QString& fileName, const QString& text,double x, double y, double height, double rotation, double oblique,int hAlign, int vAlign, double xAlign,int colour, +void Createdxf::drawTextAligned(const QString& fileName, const QString& text,double x, double y, double height, double rotation, double oblique,int hAlign, int vAlign, double xAlign, double xScale, int colour, bool leftAlign, float scale) { Q_UNUSED(scale); @@ -774,6 +774,8 @@ void Createdxf::drawTextAligned(const QString& fileName, const QString& text,dou To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates To_Dxf << 40 << "\r\n"; To_Dxf << height << "\r\n"; // Text Height + To_Dxf << 41 << "\r\n"; + To_Dxf << xScale << "\r\n"; // X Scale To_Dxf << 1 << "\r\n"; To_Dxf << text << "\r\n"; // Text Value To_Dxf << 50 << "\r\n"; diff --git a/sources/createdxf.h b/sources/createdxf.h index 60530e9d8..29554733a 100644 --- a/sources/createdxf.h +++ b/sources/createdxf.h @@ -24,13 +24,13 @@ /* This class exports the project to DXF Format */ class Createdxf -{ - public: - Createdxf(); - ~Createdxf(); - static void dxfBegin (const QString&); - static void dxfEnd(const QString&); - // you can add more functions to create more drawings. +{ + public: + Createdxf(); + ~Createdxf(); + static void dxfBegin (const QString&); + static void dxfEnd(const QString&); + // you can add more functions to create more drawings. static void drawCircle(const QString&, double, double, @@ -43,7 +43,7 @@ class Createdxf double startAngle, double endAngle, int color); - static void drawDonut(QString,double,double,double,int); + static void drawDonut(QString,double,double,double,int); static void drawArcEllipse (const QString &file_path, qreal x, @@ -97,6 +97,7 @@ class Createdxf int hAlign, int vAlign, double xAlign, + double xScale, int colour, bool leftAlign = false, float scale = 0); @@ -105,12 +106,12 @@ class Createdxf static int getcolorCode (const long red, const long green, const long blue); - static long RGBcodeTable[]; + static long RGBcodeTable[]; - static const double sheetWidth; - static const double sheetHeight; - static double xScale; - static double yScale; + static const double sheetWidth; + static const double sheetHeight; + static double xScale; + static double yScale; }; #endif // CREATEDXF_H diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index 5698a3f1e..2c98645b2 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -404,7 +404,7 @@ void ExportDialog::generateDxf(Diagram *diagram, int height, bool keep_aspect_ratio, QString &file_path) { - saveReloadDiagramParameters(diagram, true); + saveReloadDiagramParameters(diagram, true); width -= 2*Diagram::margin; height -= 2*Diagram::margin; @@ -415,22 +415,12 @@ void ExportDialog::generateDxf(Diagram *diagram, Createdxf::dxfBegin(file_path); //Add project elements (lines, rectangles, circles, texts) to dxf file - if (epw -> exportProperties().draw_border) { - double bx0 = Diagram::margin * Createdxf::xScale; - double by0 = Diagram::margin * Createdxf::yScale; - Createdxf::drawRectangle( - file_path, - bx0, - -by0, - double(width)*Createdxf::xScale, - double(height)*Createdxf::yScale, - 0); - } - diagram -> border_and_titleblock.drawDxf(width, - height, - keep_aspect_ratio, - file_path, - 0); + if (epw -> exportProperties().draw_border) { + double bx0 = Diagram::margin * Createdxf::xScale; + double by0 = Diagram::margin * Createdxf::yScale; + Createdxf::drawRectangle(file_path, bx0, -by0, double(width)*Createdxf::xScale, double(height)*Createdxf::yScale, 0); + } + diagram -> border_and_titleblock.drawDxf(width, height, keep_aspect_ratio, file_path, 0); // Build the lists of elements. QList list_elements; diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index 2117c9e0c..5b2af260f 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -1833,34 +1833,28 @@ void TitleBlockTemplate::renderTextCellDxf(QString &file_path, x2 = x; } else if ( cell.alignment & Qt::AlignBottom ) {} - //painter.setFont(text_font); - + qreal ratio = 1.0; if (cell.hadjust) { - QFontMetricsF font_metrics(text_font); - QRectF font_rect = font_metrics.boundingRect( - QRect(-10000, -10000, 10000, 10000), - cell.alignment, - text); - - if (font_rect.width()*Createdxf::xScale > w) { - qreal ratio = qreal(w) - / qreal(font_rect.width() - *Createdxf::xScale); - textHeight *= ratio; + // Scale font width to fit string in cell width w + QFontMetricsF font_metrics(text_font); + qreal textw = font_metrics.width(text)*Createdxf::xScale; + if (textw > w) { + ratio = (w / textw) * 0.8; // Allow some space around text in cell } } - + // x & y offset values below (1 & 3) currently set heuristically based on appearance... Createdxf::drawTextAligned(file_path, text, - x, - y, + x - 1*Createdxf::xScale, + y - 3*Createdxf::yScale, textHeight*Createdxf::yScale, 0, 0, hAlign, vAlign, x2, + ratio, color, 0);