Skip to content

Commit

Permalink
vports, text bugs & update to 0.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Rallaz committed Sep 10, 2012
1 parent 6ea2106 commit fce038a
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 54 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.63])
AC_INIT([libdxfrw], [0.5.3], [https://sourceforge.net/projects/libdxfrw/])
AC_INIT([libdxfrw], [0.5.4], [https://sourceforge.net/projects/libdxfrw/])
AM_INIT_AUTOMAKE([foreign -Wall -Werror dist-bzip2])
AC_CONFIG_SRCDIR([src/drw_interface.h])

Expand Down Expand Up @@ -35,7 +35,7 @@ AC_CONFIG_MACRO_DIR([m4])
# then set age to 0.
#
LIBRARY_CURRENT=5
LIBRARY_REVISION=3
LIBRARY_REVISION=4
LIBRARY_AGE=0

AC_SUBST(LIBRARY_CURRENT)dnl
Expand Down
4 changes: 2 additions & 2 deletions src/drw_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,10 @@ void DRW_Text::parseCode(int code, dxfReader *reader){
textgen = reader->getInt32();
break;
case 72:
alignH = (DRW::HAlign)reader->getInt32();
alignH = (HAlign)reader->getInt32();
break;
case 73:
alignV = (DRW::VAlign)reader->getInt32();
alignV = (VAlign)reader->getInt32();
break;
case 1:
text = reader->getUtf8String();
Expand Down
75 changes: 44 additions & 31 deletions src/drw_entities.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@ using std::string;

namespace DRW {

//! Vertical alignments.
enum VAlign {
VAlignBaseLine =0, /*!< Top. */
VAlignBottom, /*!< Bottom */
VAlignMiddle, /*!< Middle */
VAlignTop /*!< Top. */
};

//! Horizontal alignments.
enum HAlign {
HAlignLeft = 0, /*!< Left */
HAlignCenter, /*!< Centered */
HRight, /*!< Right */
HAligned, /*!< Right */
HAlignMiddle, /*!< middle */
HAlignFit /*!< fit into point */
};


//! Entity's type.
enum ETYPE {
POINT,
Expand Down Expand Up @@ -453,30 +434,48 @@ class DRW_LWPolyline : public DRW_Entity {
*/
class DRW_Text : public DRW_Line {
public:
//! Vertical alignments.
enum VAlign {
VBaseLine = 0, /*!< Top = 0 */
VBottom, /*!< Bottom = 1 */
VMiddle, /*!< Middle = 2 */
VTop /*!< Top = 3 */
};

//! Horizontal alignments.
enum HAlign {
HLeft = 0, /*!< Left = 0 */
HCenter, /*!< Centered = 1 */
HRight, /*!< Right = 2 */
HAligned, /*!< Aligned = 3 (if VAlign==0) */
HMiddle, /*!< middle = 4 (if VAlign==0) */
HFit /*!< fit into point = 5 (if VAlign==0) */
};

DRW_Text() {
eType = DRW::TEXT;
angle = 0;
widthscale = 1;
oblique = 0;
style = "STANDARD";
textgen = 0;
alignH = DRW::HAlignLeft;
alignV = DRW::VAlignBaseLine;
alignH = HLeft;
alignV = VBaseLine;
}

virtual void applyExtrusion(){} //RLZ TODO
void parseCode(int code, dxfReader *reader);

public:
double height; /*!< height text, code 40 */
UTF8STRING text; /*!< text string, code 1 */
double angle; /*!< rotation angle in degrees (360), code 50 */
double widthscale; /*!< width factor, code 41 */
double oblique; /*!< oblique angle, code 51 */
UTF8STRING style; /*!< stile name, code 7 */
int textgen; /*!< text generation, code 71 */
enum DRW::HAlign alignH; /*!< horizontal align, code 72 */
enum DRW::VAlign alignV; /*!< vertical align, code 73 */
double height; /*!< height text, code 40 */
UTF8STRING text; /*!< text string, code 1 */
double angle; /*!< rotation angle in degrees (360), code 50 */
double widthscale; /*!< width factor, code 41 */
double oblique; /*!< oblique angle, code 51 */
UTF8STRING style; /*!< stile name, code 7 */
int textgen; /*!< text generation, code 71 */
enum HAlign alignH; /*!< horizontal align, code 72 */
enum VAlign alignV; /*!< vertical align, code 73 */
};

//! Class to handle insert entries
Expand All @@ -486,10 +485,24 @@ class DRW_Text : public DRW_Line {
*/
class DRW_MText : public DRW_Text {
public:
//! Attachments.
enum Attach {
TopLeft = 1,
TopCenter,
TopRight,
MiddleLeft,
MiddleCenter,
MiddleRight,
BottomLeft,
BottomCenter,
BottomRight
};

DRW_MText() {
eType = DRW::MTEXT;
interlin = 1;
alignV = (DRW::VAlign)2;
alignV = (VAlign)TopLeft;
textgen = 1;
haveXAxis = false; //if true needed to recalculate angle
}

Expand Down
5 changes: 5 additions & 0 deletions src/drw_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ void DRW_ImageDef::parseCode(int code, dxfReader *reader){
}
}

void DRW_Header::addComment(string c){
if (!comments.empty())
comments += '\n';
comments += c;
}

void DRW_Header::parseCode(int code, dxfReader *reader){
switch (code) {
Expand Down
11 changes: 11 additions & 0 deletions src/drw_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class DRW_Vport : public DRW_TableEntry {
fastZoom = 1;
circleZoom = 100;
ucsIcon = 3;
gridBehavior = 7;
}

void parseCode(int code, dxfReader *reader);
Expand Down Expand Up @@ -310,6 +311,13 @@ class DRW_Vport : public DRW_TableEntry {
int grid; /*!< grid on/off, code 76 */
int snapStyle; /*!< snap style, code 77 */
int snapIsopair; /*!< snap isopair, code 78 */
int gridBehavior; /*!< grid behavior, code 60, undocummented */
/** code 60, bit coded possible value are
* bit 1 (1) show out of limits
* bit 2 (2) adaptive grid
* bit 3 (4) allow subdivision
* bit 4 (8) follow dinamic SCP
**/
};


Expand Down Expand Up @@ -356,6 +364,8 @@ class DRW_Header {

void parseCode(int code, dxfReader *reader);
void write(dxfWriter *writer, DRW::Version ver);
void addComment(string c);
string getComments() const {return comments;}
private:
bool getDouble(string key, double *varDouble);
bool getInt(string key, int *varInt);
Expand All @@ -365,6 +375,7 @@ class DRW_Header {
public:
std::map<string,DRW_Variant*> vars;
private:
string comments;
string name;
DRW_Variant *curr;
};
Expand Down
40 changes: 35 additions & 5 deletions src/drw_textcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

DRW_TextCodec::DRW_TextCodec() {
version = DRW::AC1021;
cp = "ANSI_1252";
conv = new DRW_Converter(NULL, 0);
}

Expand All @@ -24,12 +23,17 @@ void DRW_TextCodec::setVersion(std::string *v){
version = DRW::AC1009;
cp = "ANSI_1252";
setCodePage(&cp);
}
else if (versionStr == "AC1012" || versionStr == "AC1014"
|| versionStr == "AC1015" || versionStr == "AC1018")
} else if (versionStr == "AC1012" || versionStr == "AC1014"
|| versionStr == "AC1015" || versionStr == "AC1018") {
version = DRW::AC1015;
else
if (cp.empty()) { //codepage not set, initialize
cp = "ANSI_1252";
setCodePage(&cp);
}
} else {
version = DRW::AC1021;
cp = "ANSI_1252";
}
}

void DRW_TextCodec::setCodePage(std::string *c){
Expand Down Expand Up @@ -84,6 +88,32 @@ std::string DRW_TextCodec::fromUtf8(std::string s) {
return conv->fromUtf8(&s);
}

std::string DRW_Converter::toUtf8(std::string *s) {
std::string result;
int j = 0;
unsigned int i= 0;
for (i=0; i < s->length(); i++) {
unsigned char c = s->at(i);
if (c < 0x80) { //ascii check for /U+????
if (c == '\\' && i+6 < s->length() && s->at(i+1) == 'U' && s->at(i+2) == '+') {
result += s->substr(j,i-j);
result += encodeText(s->substr(i,7));
i +=6;
j = i+1;
}
} else if (c < 0xE0 ) {//2 bits
i++;
} else if (c < 0xF0 ) {//3 bits
i +=2;
} else if (c < 0xF8 ) {//4 bits
i +=3;
}
}
result += s->substr(j);

return result;
}

std::string DRW_ConvTable::fromUtf8(std::string *s) {
std::string result;
bool notFound;
Expand Down
2 changes: 1 addition & 1 deletion src/drw_textcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DRW_Converter
DRW_Converter(const int *t, int l){table = t;
cpLenght = l;}
virtual std::string fromUtf8(std::string *s) {return *s;}
virtual std::string toUtf8(std::string *s) {return *s;}
virtual std::string toUtf8(std::string *s);
std::string encodeText(std::string stmp);
std::string decodeText(int c);
std::string encodeNum(int c);
Expand Down
28 changes: 16 additions & 12 deletions src/libdxfrw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ bool dxfRW::writeVport(DRW_Vport *ent){
writer->writeDouble(146, 0.0);
if (version > DRW::AC1018) {
writer->writeString(348, "10020");
writer->writeInt16(60, 3);//v2007 undocummented
writer->writeInt16(60, ent->gridBehavior);//v2007 undocummented see DRW_Vport class
writer->writeInt16(61, 5);
writer->writeBool(292, 1);
writer->writeInt16(282, 1);
Expand Down Expand Up @@ -910,10 +910,14 @@ bool dxfRW::writeHatch(DRW_Hatch *ent){
}
writer->writeInt16(75, ent->hstyle);
writer->writeInt16(76, ent->hpattern);
writer->writeDouble(52, ent->angle);
writer->writeDouble(41, ent->scale);
writer->writeInt16(77, ent->doubleflag);
writer->writeInt16(78, ent->deflines);
if (!ent->solid){
writer->writeDouble(52, ent->angle);
writer->writeDouble(41, ent->scale);
writer->writeInt16(77, ent->doubleflag);
}
if (ent->deflines > 0){
writer->writeInt16(78, ent->deflines);
}
writer->writeInt16(98, 0);
} else {
//RLZ: TODO verify in acad12
Expand Down Expand Up @@ -1107,10 +1111,10 @@ bool dxfRW::writeText(DRW_Text *ent){
else
writer->writeUtf8Caps(7, ent->style);
writer->writeInt16(71, ent->textgen);
if (ent->alignH != DRW::HAlignLeft) {
if (ent->alignH != DRW_Text::HLeft) {
writer->writeInt16(72, ent->alignH);
}
if (ent->alignH != DRW::HAlignLeft || ent->alignV != DRW::VAlignBaseLine) {
if (ent->alignH != DRW_Text::HLeft || ent->alignV != DRW_Text::VBaseLine) {
writer->writeDouble(11, ent->secPoint.x);
writer->writeDouble(21, ent->secPoint.y);
writer->writeDouble(31, ent->secPoint.z);
Expand All @@ -1121,7 +1125,7 @@ bool dxfRW::writeText(DRW_Text *ent){
if (version > DRW::AC1009) {
writer->writeString(100, "AcDbText");
}
if (ent->alignV != DRW::VAlignBaseLine) {
if (ent->alignV != DRW_Text::VBaseLine) {
writer->writeInt16(73, ent->alignV);
}
return true;
Expand Down Expand Up @@ -1723,7 +1727,9 @@ bool dxfRW::processDxf() {
// section = secUnknown;
while (reader->readRec(&code, !binary)) {
DBG(code); DBG(" processDxf\n");
if (code == 0) {
if (code == 999) {
header.addComment(reader->getString());
} else if (code == 0) {
sectionstr = reader->getString();
DBG(sectionstr); DBG(" processDxf\n");
if (sectionstr == "EOF") {
Expand Down Expand Up @@ -1801,9 +1807,7 @@ bool dxfRW::processTables() {
sectionstr = reader->getString();
DBG(sectionstr); DBG(" processHeader\n\n");
//found section, process it
if (sectionstr == "VPORT") {
// processVPort();
} else if (sectionstr == "LTYPE") {
if (sectionstr == "LTYPE") {
processLType();
} else if (sectionstr == "LAYER") {
processLayer();
Expand Down
2 changes: 1 addition & 1 deletion src/libdxfrw.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "drw_objects.h"
#include "drw_interface.h"

#define DRW_VERSION "0.5.2"
#define DRW_VERSION "0.5.4"

class dxfReader;
class dxfWriter;
Expand Down

0 comments on commit fce038a

Please sign in to comment.