Skip to content

Commit 066e25d

Browse files
Merge pull request #2148 from KLayout/feature/issue-2145
Implemented solution for issue #2145 (default_text_size option for GD…
2 parents 71929bf + 712237e commit 066e25d

File tree

12 files changed

+258
-58
lines changed

12 files changed

+258
-58
lines changed

src/buddies/src/bd/bdWriterOptions.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ GenericWriterOptions::GenericWriterOptions ()
5050
m_gds2_write_timestamps = save_options.get_option_by_name ("gds2_write_timestamps").to_bool ();
5151
m_gds2_write_cell_properties = save_options.get_option_by_name ("gds2_write_cell_properties").to_bool ();
5252
m_gds2_write_file_properties = save_options.get_option_by_name ("gds2_write_file_properties").to_bool ();
53+
tl::Variant def_text_size = save_options.get_option_by_name ("gds2_default_text_size");
54+
m_gds2_default_text_size = def_text_size.is_nil () ? -1.0 : def_text_size.to_double ();
5355

5456
m_oasis_compression_level = save_options.get_option_by_name ("oasis_compression_level").to_int ();
5557
m_oasis_write_cblocks = save_options.get_option_by_name ("oasis_write_cblocks").to_bool ();
@@ -201,6 +203,13 @@ GenericWriterOptions::add_options (tl::CommandLineOptions &cmd, const std::strin
201203
"This option enables a GDS2 extension that allows writing of file properties to GDS2 files. "
202204
"Consumers that don't support this feature, may not be able to read such a GDS2 files."
203205
)
206+
<< tl::arg (group +
207+
"#--default-text-size", &m_gds2_default_text_size, "Default text size",
208+
"This text size (given in micrometers) is applied to text objects not coming with their "
209+
"own text size (technically: with a zero text size). It can be set to 0 to preserve an original "
210+
"text size of zero. This option is also handy to give text objects from OASIS files a "
211+
"specific size. By default, text objects without a size (i.e. with a zero size) do not receive one."
212+
)
204213
;
205214

206215
}
@@ -379,6 +388,7 @@ GenericWriterOptions::configure (db::SaveLayoutOptions &save_options, const db::
379388
save_options.set_option_by_name ("gds2_write_timestamps", m_gds2_write_timestamps);
380389
save_options.set_option_by_name ("gds2_write_cell_properties", m_gds2_write_cell_properties);
381390
save_options.set_option_by_name ("gds2_write_file_properties", m_gds2_write_file_properties);
391+
save_options.set_option_by_name ("gds2_default_text_size", m_gds2_default_text_size < 0.0 ? tl::Variant () : tl::Variant (m_gds2_default_text_size));
382392

383393
save_options.set_option_by_name ("oasis_compression_level", m_oasis_compression_level);
384394
save_options.set_option_by_name ("oasis_write_cblocks", m_oasis_write_cblocks);

src/buddies/src/bd/bdWriterOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class BD_PUBLIC GenericWriterOptions
123123
bool m_gds2_write_timestamps;
124124
bool m_gds2_write_cell_properties;
125125
bool m_gds2_write_file_properties;
126+
double m_gds2_default_text_size;
126127

127128
int m_oasis_compression_level;
128129
bool m_oasis_write_cblocks;

src/buddies/unit_tests/bdBasicTests.cc

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ TEST(1)
8282
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_multi_xy_records").to_bool (), false);
8383
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_write_timestamps").to_bool (), true);
8484
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_no_zero_length_paths").to_bool (), false);
85-
EXPECT_EQ (tl::to_string (stream_opt.get_option_by_name ("gds2_user_units").to_double ()), "1");
85+
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_user_units").to_double (), 1.0);
8686
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_write_cell_properties").to_bool (), false);
8787
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_write_file_properties").to_bool (), false);
88+
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_default_text_size").to_string (), "nil");
8889
EXPECT_EQ (stream_opt.get_option_by_name ("oasis_write_cblocks").to_bool (), true);
8990
EXPECT_EQ (stream_opt.get_option_by_name ("oasis_compression_level").to_int (), 2);
9091
EXPECT_EQ (stream_opt.get_option_by_name ("oasis_strict_mode").to_bool (), true);
@@ -107,9 +108,10 @@ TEST(1)
107108
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_multi_xy_records").to_bool (), true);
108109
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_write_timestamps").to_bool (), false);
109110
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_no_zero_length_paths").to_bool (), true);
110-
EXPECT_EQ (tl::to_string (stream_opt.get_option_by_name ("gds2_user_units").to_double ()), "2.5");
111+
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_user_units").to_double (), 2.5);
111112
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_write_cell_properties").to_bool (), true);
112113
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_write_file_properties").to_bool (), true);
114+
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_default_text_size").to_string (), "nil");
113115
EXPECT_EQ (stream_opt.get_option_by_name ("oasis_write_cblocks").to_bool (), false);
114116
EXPECT_EQ (stream_opt.get_option_by_name ("oasis_compression_level").to_int (), 9);
115117
EXPECT_EQ (stream_opt.get_option_by_name ("oasis_strict_mode").to_bool (), false);
@@ -118,6 +120,52 @@ TEST(1)
118120
EXPECT_EQ (stream_opt.get_option_by_name ("oasis_write_std_properties_ext").to_int (), 2);
119121
}
120122

123+
// Testing writer options (default_text_size)
124+
TEST(2)
125+
{
126+
bd::GenericWriterOptions opt;
127+
tl::CommandLineOptions cmd;
128+
129+
opt.add_options (cmd);
130+
131+
const char *argv[] = {
132+
"x",
133+
"--default-text-size=1.25",
134+
};
135+
136+
cmd.parse (sizeof (argv) / sizeof (argv[0]), const_cast<char **> (argv));
137+
138+
db::Layout layout;
139+
140+
db::SaveLayoutOptions stream_opt;
141+
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_default_text_size").to_string (), "nil");
142+
opt.configure (stream_opt, layout);
143+
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_default_text_size").to_string (), "1.25");
144+
}
145+
146+
// Testing writer options (default_text_size)
147+
TEST(3)
148+
{
149+
bd::GenericWriterOptions opt;
150+
tl::CommandLineOptions cmd;
151+
152+
opt.add_options (cmd);
153+
154+
const char *argv[] = {
155+
"x",
156+
"--default-text-size=-1",
157+
};
158+
159+
cmd.parse (sizeof (argv) / sizeof (argv[0]), const_cast<char **> (argv));
160+
161+
db::Layout layout;
162+
163+
db::SaveLayoutOptions stream_opt;
164+
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_default_text_size").to_string (), "nil");
165+
opt.configure (stream_opt, layout);
166+
EXPECT_EQ (stream_opt.get_option_by_name ("gds2_default_text_size").to_string (), "nil");
167+
}
168+
121169
static std::string cells2string (const db::Layout &layout, const std::set<db::cell_index_type> &cells)
122170
{
123171
std::string res;
@@ -131,7 +179,7 @@ static std::string cells2string (const db::Layout &layout, const std::set<db::ce
131179
}
132180

133181
// Testing writer options: cell resolution
134-
TEST(2)
182+
TEST(4)
135183
{
136184
// Build a layout with the hierarchy
137185
// TOP -> A, B

src/plugins/streamers/gds2/db_plugin/dbGDS2.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class GDS2FormatDeclaration
7373
tl::make_member (&db::GDS2WriterOptions::write_cell_properties, "write-cell-properties") +
7474
tl::make_member (&db::GDS2WriterOptions::write_file_properties, "write-file-properties") +
7575
tl::make_member (&db::GDS2WriterOptions::no_zero_length_paths, "no-zero-length-paths") +
76+
tl::make_member (&db::GDS2WriterOptions::default_text_size, "default-text-size") +
7677
tl::make_member (&db::GDS2WriterOptions::multi_xy_records, "multi-xy-records") +
7778
tl::make_member (&db::GDS2WriterOptions::resolve_skew_arrays, "resolve-skew-arrays") +
7879
tl::make_member (&db::GDS2WriterOptions::max_vertex_count, "max-vertex-count") +

src/plugins/streamers/gds2/db_plugin/dbGDS2Format.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ class DB_PLUGIN_PUBLIC GDS2WriterOptions
115115
user_units (1.0),
116116
write_timestamps (true),
117117
write_cell_properties (false),
118-
write_file_properties (false)
118+
write_file_properties (false),
119+
default_text_size (-1.0)
119120
{
120121
// .. nothing yet ..
121122
}
@@ -191,6 +192,14 @@ class DB_PLUGIN_PUBLIC GDS2WriterOptions
191192
*/
192193
bool write_file_properties;
193194

195+
/**
196+
* @brief The default text size if none is given (in fact, if the text size is zero)
197+
*
198+
* You can set to option to 0 to preserve the zero text size on writing.
199+
* A negative value means the text size is not set if missing.
200+
*/
201+
double default_text_size;
202+
194203
/**
195204
* @brief Implementation of FormatSpecificWriterOptions
196205
*/

src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static uint16_t safe_convert_to_uint16 (uint64_t value)
155155

156156
GDS2WriterBase::GDS2WriterBase ()
157157
: m_dbu (0.0), m_resolve_skew_arrays (false), m_multi_xy (false), m_no_zero_length_paths (false),
158-
m_max_vertex_count (0), m_write_cell_properties (false), m_keep_instances (false)
158+
m_max_vertex_count (0), m_write_cell_properties (false), m_keep_instances (false), m_default_text_size (-1.0)
159159
{
160160
// .. nothing yet ..
161161
}
@@ -481,6 +481,7 @@ GDS2WriterBase::write (db::Layout &layout, tl::OutputStream &stream, const db::S
481481
m_no_zero_length_paths = gds2_options.no_zero_length_paths;
482482
m_resolve_skew_arrays = gds2_options.resolve_skew_arrays;
483483
m_write_cell_properties = gds2_options.write_cell_properties;
484+
m_default_text_size = gds2_options.default_text_size;
484485

485486
size_t max_cellname_length = std::max (gds2_options.max_cellname_length, (unsigned int)8);
486487

@@ -902,7 +903,7 @@ GDS2WriterBase::write_text (int layer, int datatype, double sf, double dbu, cons
902903
write_short (ha + va * 4 + f * 16);
903904
}
904905

905-
if (trans.rot () != 0 || shape.text_size () != 0) {
906+
if (trans.rot () != 0 || shape.text_size () != 0 || m_default_text_size >= 0.0) {
906907

907908
write_record_size (6);
908909
write_record (sSTRANS);
@@ -912,6 +913,10 @@ GDS2WriterBase::write_text (int layer, int datatype, double sf, double dbu, cons
912913
write_record_size (4 + 8);
913914
write_record (sMAG);
914915
write_double (shape.text_size () * sf * dbu);
916+
} else if (m_default_text_size >= 0.0) {
917+
write_record_size (4 + 8);
918+
write_record (sMAG);
919+
write_double (m_default_text_size * sf);
915920
}
916921

917922
if ((trans.rot () % 4) != 0) {

src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class DB_PLUGIN_PUBLIC GDS2WriterBase
174174
size_t m_max_vertex_count;
175175
bool m_write_cell_properties;
176176
bool m_keep_instances;
177+
double m_default_text_size;
177178

178179
void write_properties (const db::Layout &layout, db::properties_id_type prop_id);
179180
void write_context_cell (db::Layout &layout, const short *time_data, const std::vector<cell_index_type> &cells);

src/plugins/streamers/gds2/db_plugin/gsiDeclDbGDS2.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ static bool get_gds2_write_timestamps (const db::SaveLayoutOptions *options)
115115
return options->get_options<db::GDS2WriterOptions> ().write_timestamps;
116116
}
117117

118+
static void set_gds2_default_text_size (db::SaveLayoutOptions *options, const tl::Variant &v)
119+
{
120+
options->get_options<db::GDS2WriterOptions> ().default_text_size = v.is_nil () ? -1.0 : v.to_double ();
121+
}
122+
123+
static tl::Variant get_gds2_default_text_size (const db::SaveLayoutOptions *options)
124+
{
125+
double ts = options->get_options<db::GDS2WriterOptions> ().default_text_size;
126+
return ts < 0.0 ? tl::Variant () : tl::Variant (ts);
127+
}
128+
118129
static void set_gds2_libname (db::SaveLayoutOptions *options, const std::string &n)
119130
{
120131
options->get_options<db::GDS2WriterOptions> ().libname = n;
@@ -189,6 +200,22 @@ gsi::ClassExt<db::SaveLayoutOptions> gds2_writer_options (
189200
"@brief Gets a value indicating whether the current time is written into the GDS2 timestamp fields\n"
190201
"\nThis property has been added in version 0.21.16.\n"
191202
) +
203+
gsi::method_ext ("gds2_default_text_size=", &set_gds2_default_text_size, gsi::arg ("size"),
204+
"@brief Specifies the default text size to use when a text does not have a size\n"
205+
"\n"
206+
"Text object can have no size, e.g. when they are read from OASIS files. Technically such texts\n"
207+
"are represented by text object with a zero size. You can configure the GDS writer to use a specific\n"
208+
"text size in this case. This property specifies the default text size in micrometer units. This\n"
209+
"size can be set to 0 to preserve a zero size in GDS files read.\n"
210+
"\n"
211+
"Set this attribute to nil to disable writing of a text size if none is specified.\n"
212+
"\n"
213+
"\nThis property has been added in version 0.30.4.\n"
214+
) +
215+
gsi::method_ext ("gds2_default_text_size", &get_gds2_default_text_size,
216+
"@brief Gets the default text size to use when a text does not have a size\n"
217+
"\nThis property has been added in version 0.30.4.\n"
218+
) +
192219
gsi::method_ext ("gds2_no_zero_length_paths=", &set_gds2_no_zero_length_paths, gsi::arg ("flag"),
193220
"@brief Eliminates zero-length paths if true\n"
194221
"\n"

0 commit comments

Comments
 (0)