Skip to content

Commit 6d8177b

Browse files
committed
Added the "-name_is_filename" command-line option
1 parent ffa8e89 commit 6d8177b

File tree

8 files changed

+80
-120
lines changed

8 files changed

+80
-120
lines changed

Docs/Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
Usage: Gerber2pdf [-silentexit] [-nowarnings] [-CMYK] ...
55
[-output=output_file_name] ...
66
[-background=R,G,B[,A]] [-backgroundCMYK=C,M,Y,K[,A]] ...
7-
[-strokes2fills] [-page_size=extents|A3|A4|letter] ...
7+
[-strokes2fills] [-name_is_filename] ...
8+
[-page_size=extents|A3|A4|letter] ...
89
[-orientation=portrait|landscape] [-scale_to_fit] ...
910
[-next_page_size=extents|A3|A4|letter] ...
1011
[-next_orientation=portrait|landscape] [-next_scale_to_fit] ...
@@ -47,6 +48,9 @@ The -strokes2fills option converts all strokes to fills for the next
4748
file, thereby converting outlines to areas. It resets to default
4849
after that file.
4950
51+
The -name_is_filename option forces the PDF bookmarks to use
52+
the filename instead of the IN or LN commands.
53+
5054
The -page_size option takes global effect and can have one of 4 values:
5155
"extents", "A3", "A4" or "letter"
5256

Engine/Engine.cpp

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ using namespace std;
2525
//------------------------------------------------------------------------------
2626

2727
ENGINE::COLOUR::COLOUR(){
28-
UseCMYK = false;
29-
R = G = B = A = 0;
28+
R = G = B = 0;
3029
C = M = Y = K = 0;
3130
}
3231
//------------------------------------------------------------------------------
@@ -74,8 +73,6 @@ ENGINE::OPAQUE_STACK::~OPAQUE_STACK(){
7473
//------------------------------------------------------------------------------
7574

7675
ENGINE::LEVEL_FORM::LEVEL_FORM(){
77-
Level = 0;
78-
Next = 0;
7976
}
8077
//------------------------------------------------------------------------------
8178

@@ -86,10 +83,6 @@ ENGINE::LEVEL_FORM::~LEVEL_FORM(){
8683
//------------------------------------------------------------------------------
8784

8885
ENGINE::LAYER::LAYER(){
89-
Filename = 0;
90-
ConvertStrokesToFills = false;
91-
Form = 0;
92-
Next = 0;
9386
}
9487
//------------------------------------------------------------------------------
9588

@@ -127,62 +120,10 @@ ENGINE::OUTLINE::~OUTLINE(){
127120
//------------------------------------------------------------------------------
128121

129122
ENGINE::ENGINE(){
130-
ConvertStrokesToFills = false;
131-
ScaleToFit = false;
132-
NextScaleToFit = false;
133-
UseCMYK = false;
134-
135-
PageSize = PS_Tight;
136-
Orientation = PO_Auto;
137-
138-
NextPageSize = PS_Tight;
139-
NextOrientation = PO_Auto;
140-
141-
OpaqueCount = 0;
142-
OpaqueStack = 0;
143-
144-
Layers = 0;
145-
146-
Mirror = false;
147-
Negative = false;
148-
149123
Light.R = 1.0; Light.G = 1.0; Light.B = 1.0; Light.A = 0.0;
150124
Dark .R = 0.0; Dark .G = 0.0; Dark .B = 0.0; Dark .A = 1.0;
151125

152-
ApertureStack = 0;
153-
154-
ApertureCount = 0;
155-
CurrentAperture = 0;
156-
157-
SolidCircle = false;
158-
SolidRectangle = false;
159-
OutlinePath = false;
160-
LineWidth = 0.0;
161-
RectW = 0.0;
162-
RectH = 0.0;
163-
RectX = 0.0;
164-
RectY = 0.0;
165-
166126
Opaque = new pdfOpaque("Opaque");
167-
168-
PageCount = 0;
169-
Combine = false;
170-
NewPage = true;
171-
ThePageUsed = false;
172-
ThePageLeft = 1e100;
173-
ThePageBottom = 1e100;
174-
ThePageRight = -1e100;
175-
ThePageTop = -1e100;
176-
177-
LevelStack = 0;
178-
LevelCount = 0;
179-
180-
ThePage = 0;
181-
TheContents = 0;
182-
183-
Page = 0;
184-
Outline = 0;
185-
186127
Opaque->Opacity(1.0);
187128
pdf.AddIndirect(Opaque);
188129
}
@@ -787,7 +728,7 @@ int ENGINE::Run(const char* FileName, const char* Title){
787728
ConvertStrokesToFills = false;
788729
return 0;
789730
}
790-
if(Gerber.Name){
731+
if(!NameIsFilename && Gerber.Name){
791732
Layer->Title.assign(Gerber.Name);
792733
}else{
793734
for(
@@ -949,7 +890,7 @@ int ENGINE::Run(const char* FileName, const char* Title){
949890

950891
LevelStack->Level->Resources.AddOpaque(Opaque);
951892
Apertures.clear();
952-
Result = RenderLayer(LevelStack->Level, LevelStack->Level, Level);
893+
int Result = RenderLayer(LevelStack->Level, LevelStack->Level, Level);
953894
if(Result) return Result;
954895

955896
Layer->Form->Push();
@@ -975,7 +916,7 @@ int ENGINE::Run(const char* FileName, const char* Title){
975916

976917
}else{
977918
Layer->Form->Resources.AddOpaque(Opaque);
978-
Result = RenderLayer(Layer->Form, Layer->Form, Level);
919+
int Result = RenderLayer(Layer->Form, Layer->Form, Level);
979920
if(Result) return Result;
980921
}
981922

Engine/Engine.h

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -43,66 +43,71 @@ struct ENGINE{
4343
PS_A3,
4444
PS_A4,
4545
PS_Letter
46-
} PageSize, NextPageSize;
46+
};
47+
PAGE_SIZE PageSize = PS_Tight;
48+
PAGE_SIZE NextPageSize = PS_Tight;
4749

4850
enum PAGE_ORIENTATION{
4951
PO_Auto = 0,
5052
PO_Portrait,
5153
PO_Landscape
52-
} Orientation, NextOrientation;
54+
};
55+
PAGE_ORIENTATION Orientation = PO_Auto;
56+
PAGE_ORIENTATION NextOrientation = PO_Auto;
5357

54-
bool Mirror;
55-
bool Combine;
56-
bool NewPage;
58+
bool Mirror = false;
59+
bool Combine = false;
60+
bool NewPage = true;
5761

5862
struct COLOUR{
59-
bool UseCMYK;
63+
bool UseCMYK = false;
6064
union{
6165
struct{ double R, G, B; };
6266
struct{ double C, M, Y, K; };
6367
};
64-
double A;
68+
double A = 0;
6569
COLOUR();
6670
void operator= (COLOUR& Colour);
6771
bool operator== (COLOUR& Colour);
6872
} Light, Dark;
6973

70-
bool ConvertStrokesToFills;
71-
bool ScaleToFit;
72-
bool NextScaleToFit;
73-
bool UseCMYK;
74-
//------------------------------------------------------------------------------
74+
bool ConvertStrokesToFills = false;
75+
bool ScaleToFit = false;
76+
bool NextScaleToFit = false;
77+
bool UseCMYK = false;
78+
bool NameIsFilename = false;
79+
//--------------------------------------------------------------------------
7580

7681
private: // Internal structures
77-
int OpaqueCount;
82+
int OpaqueCount = 0;
7883
struct OPAQUE_STACK{
7984
pdfOpaque* Opaque;
8085
OPAQUE_STACK* Next;
8186

8287
OPAQUE_STACK(double Value, int& OpaqueCount);
8388
~OPAQUE_STACK();
8489
};
85-
OPAQUE_STACK* OpaqueStack;
90+
OPAQUE_STACK* OpaqueStack = 0;
8691

8792
struct APERTURE{
8893
pdfForm* Aperture;
8994
APERTURE* Next;
9095
};
9196

9297
struct LEVEL_FORM{
93-
pdfForm* Level;
94-
LEVEL_FORM* Next;
98+
pdfForm* Level = 0;
99+
LEVEL_FORM* Next = 0;
95100

96101
LEVEL_FORM();
97102
~LEVEL_FORM();
98103
};
99104

100105
struct LAYER{
101-
char* Filename;
102-
bool ConvertStrokesToFills;
106+
char* Filename = 0;
107+
bool ConvertStrokesToFills = false;
103108
COLOUR Light;
104-
pdfForm* Form;
105-
LAYER* Next;
109+
pdfForm* Form = 0;
110+
LAYER* Next = 0;
106111

107112
bool Negative;
108113
double Left, Bottom, Right, Top;
@@ -111,7 +116,7 @@ struct ENGINE{
111116
LAYER();
112117
~LAYER();
113118
};
114-
LAYER* Layers; // Stack of layer XObjects
119+
LAYER* Layers = 0; // Stack of layer XObjects
115120

116121
// These stacks keep track of objects to be deleted at the end
117122
struct PAGE{
@@ -125,7 +130,7 @@ struct ENGINE{
125130
PAGE(PAGE* Next, bool UseCMYK);
126131
~PAGE();
127132
};
128-
PAGE* Page;
133+
PAGE* Page = 0;
129134

130135
struct OUTLINE{
131136
pdfOutlineItems* Item;
@@ -134,50 +139,49 @@ struct ENGINE{
134139
OUTLINE(OUTLINE* Next);
135140
~OUTLINE();
136141
};
137-
OUTLINE* Outline;
138-
//------------------------------------------------------------------------------
142+
OUTLINE* Outline = 0;
143+
//--------------------------------------------------------------------------
139144

140145
private: // Internal State
141146
JPDF pdf;
142147

143148
// Use an associative array because the Gerber apertures need not be contiguous
144149
typedef std::map<int, pdfForm*> pdfFormArray;
145150

146-
APERTURE* ApertureStack;
147-
int ApertureCount;
151+
APERTURE* ApertureStack = 0;
152+
int ApertureCount = 0;
148153
pdfFormArray Apertures;
149-
pdfForm* CurrentAperture;
154+
pdfForm* CurrentAperture = 0;
150155

151156
pdfOpaque* Opaque;
152157

153-
bool Negative;
154-
bool SolidCircle;
155-
bool SolidRectangle;
156-
bool OutlinePath;
157-
double LineWidth;
158-
double RectW;
159-
double RectH;
160-
double RectX;
161-
double RectY;
162-
163-
int PageCount;
164-
int Result;
165-
bool ThePageUsed;
166-
double ThePageLeft;
167-
double ThePageBottom;
168-
double ThePageRight;
169-
double ThePageTop;
158+
bool Negative = false;
159+
bool SolidCircle = false;
160+
bool SolidRectangle = false;
161+
bool OutlinePath = false;
162+
double LineWidth = 0.0;
163+
double RectW = 0.0;
164+
double RectH = 0.0;
165+
double RectX = 0.0;
166+
double RectY = 0.0;
167+
168+
int PageCount = 0;
169+
bool ThePageUsed = false;
170+
double ThePageLeft = 1e100;
171+
double ThePageBottom = 1e100;
172+
double ThePageRight = -1e100;
173+
double ThePageTop = -1e100;
170174

171175
// PDF Variables and Structures
172176
pdfPages Pages; // Single level page tree
173177
pdfOutlines Outlines; // Single level outline tree
174178

175-
LEVEL_FORM* LevelStack;
176-
int LevelCount;
179+
LEVEL_FORM* LevelStack = 0;
180+
int LevelCount = 0;
177181

178-
pdfPage* ThePage; // Page on which to combine outputs
179-
pdfContents* TheContents; // Contents of ThePage
180-
//------------------------------------------------------------------------------
182+
pdfPage* ThePage = 0; // Page on which to combine outputs
183+
pdfContents* TheContents = 0; // Contents of ThePage
184+
//--------------------------------------------------------------------------
181185

182186
private: // Functions
183187
void DrawAperture(
@@ -213,7 +217,7 @@ struct ENGINE{
213217
PAGE* Page,
214218
double Left, double Bottom, double Right, double Top
215219
);
216-
//------------------------------------------------------------------------------
220+
//--------------------------------------------------------------------------
217221

218222
public: // Functions
219223
ENGINE();

Engine/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Libraries =
2727
LibInclude =
2828
#-------------------------------------------------------------------------------
2929

30-
Version = -DMAJOR_VERSION=1 -DMINOR_VERSION=12
30+
Version = -DMAJOR_VERSION=1 -DMINOR_VERSION=13
3131

3232
Objects = $(shell find Tools -iname "*.cpp")
3333
Objects += $(shell find Toolbox/Cpp -iname "*.cpp")

Engine/Tools/Gerber/JGerber.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define DEBUG
2-
31
//==============================================================================
42
// Copyright (C) John-Philip Taylor
53
// jpt13653903@gmail.com

Engine/main.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static bool StringStart(const char* String, const char* Start){
8787
int main(int argc, const char** argv){
8888
#endif
8989

90-
setupTerminal();
90+
// No longer required on newer Windows terminals
91+
// setupTerminal();
9192

9293
ENGINE Engine;
9394

@@ -123,7 +124,8 @@ static bool StringStart(const char* String, const char* Start){
123124
"Usage: Gerber2pdf [-silentexit] [-nowarnings] [-CMYK] ...\n"
124125
" [-output=output_file_name] ...\n"
125126
" [-background=R,G,B[,A]] [-backgroundCMYK=C,M,Y,K[,A]] ...\n"
126-
" [-strokes2fills] [-page_size=extents|A3|A4|letter] ...\n"
127+
" [-strokes2fills] [-name_is_filename] ...\n"
128+
" [-page_size=extents|A3|A4|letter] ...\n"
127129
" [-orientation=portrait|landscape] [-scale_to_fit] ...\n"
128130
" [-next_page_size=extents|A3|A4|letter] ...\n"
129131
" [-next_orientation=portrait|landscape] [-next_scale_to_fit] ...\n"
@@ -166,6 +168,9 @@ static bool StringStart(const char* String, const char* Start){
166168
"file, thereby converting outlines to areas. It resets to default\n"
167169
"after that file.\n"
168170
"\n"
171+
"The -name_is_filename option forces the PDF bookmarks to use\n"
172+
"the filename instead of the IN or LN commands.\n"
173+
"\n"
169174
"The -page_size option takes global effect and can have one of 4 values:\n"
170175
" \"extents\", \"A3\", \"A4\" or \"letter\"\n"
171176
"\n"
@@ -338,6 +343,9 @@ static bool StringStart(const char* String, const char* Start){
338343
}else if(!strcmp(argv[arg]+1, "strokes2fills")){
339344
Engine.ConvertStrokesToFills = true;
340345

346+
}else if(!strcmp(argv[arg]+1, "name_is_filename")){
347+
Engine.NameIsFilename = true;
348+
341349
}else if(StringStart(argv[arg]+1, "page_size=")){
342350
if (!strcmp(argv[arg]+11, "extents")) Engine.PageSize = ENGINE::PS_Extents;
343351
else if(!strcmp(argv[arg]+11, "A3" )) Engine.PageSize = ENGINE::PS_A3;

0 commit comments

Comments
 (0)