mirror of https://github.com/KLayout/klayout.git
Merge pull request #1443 from KLayout/issue-1441
Fixed issue #1441 (RDB support for text attributes like size, font, h…
This commit is contained in:
commit
112d0843a7
|
|
@ -579,8 +579,8 @@ Path round_path_corners (const Path &path, int rad, int n)
|
||||||
return Path (round_path_corners (db::DPath (path), double (rad), n, 0.5));
|
return Path (round_path_corners (db::DPath (path), double (rad), n, 0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
template class path<Coord>;
|
template class DB_PUBLIC path<Coord>;
|
||||||
template class path<DCoord>;
|
template class DB_PUBLIC path<DCoord>;
|
||||||
|
|
||||||
// explicit instantiations
|
// explicit instantiations
|
||||||
template DB_PUBLIC void path<Coord>::create_shifted_points (Coord, Coord, Coord, bool, path<Coord>::pointlist_type::iterator, path<Coord>::pointlist_type::iterator, int, box_inserter<path<Coord>::box_type>) const;
|
template DB_PUBLIC void path<Coord>::create_shifted_points (Coord, Coord, Coord, bool, path<Coord>::pointlist_type::iterator, path<Coord>::pointlist_type::iterator, int, box_inserter<path<Coord>::box_type>) const;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,61 @@
|
||||||
namespace db
|
namespace db
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static char halign2code (db::HAlign ha)
|
||||||
|
{
|
||||||
|
if (ha == db::HAlignCenter) {
|
||||||
|
return 'c';
|
||||||
|
} else if (ha == db::HAlignLeft) {
|
||||||
|
return 'l';
|
||||||
|
} else if (ha == db::HAlignRight) {
|
||||||
|
return 'r';
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static db::HAlign extract_halign (tl::Extractor &ex)
|
||||||
|
{
|
||||||
|
if (ex.test ("c")) {
|
||||||
|
return db::HAlignCenter;
|
||||||
|
} else if (ex.test ("l")) {
|
||||||
|
return db::HAlignLeft;
|
||||||
|
} else if (ex.test ("r")) {
|
||||||
|
return db::HAlignRight;
|
||||||
|
} else {
|
||||||
|
return db::NoHAlign;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static char valign2code (db::VAlign va)
|
||||||
|
{
|
||||||
|
if (va == db::VAlignCenter) {
|
||||||
|
return 'c';
|
||||||
|
} else if (va == db::VAlignBottom) {
|
||||||
|
return 'b';
|
||||||
|
} else if (va == db::VAlignTop) {
|
||||||
|
return 't';
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static db::VAlign extract_valign (tl::Extractor &ex)
|
||||||
|
{
|
||||||
|
if (ex.test ("c")) {
|
||||||
|
return db::VAlignCenter;
|
||||||
|
} else if (ex.test ("t")) {
|
||||||
|
return db::VAlignTop;
|
||||||
|
} else if (ex.test ("b")) {
|
||||||
|
return db::VAlignBottom;
|
||||||
|
} else {
|
||||||
|
return db::NoVAlign;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// StringRef implementation
|
||||||
|
|
||||||
StringRef::~StringRef ()
|
StringRef::~StringRef ()
|
||||||
{
|
{
|
||||||
if (mp_rep) {
|
if (mp_rep) {
|
||||||
|
|
@ -33,19 +88,55 @@ StringRef::~StringRef ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// text implementation
|
||||||
|
|
||||||
|
template <class C>
|
||||||
|
std::string text<C>::to_string (double dbu) const
|
||||||
|
{
|
||||||
|
std::string s = std::string ("(") + tl::to_quoted_string (string ()) + "," + m_trans.to_string (dbu) + ")";
|
||||||
|
|
||||||
|
if (size () > 0) {
|
||||||
|
s += " s=";
|
||||||
|
s += tl::to_string (size ());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (font () >= 0) {
|
||||||
|
s += " f=";
|
||||||
|
s += tl::to_string (int (font ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
char c;
|
||||||
|
c = halign2code (halign ());
|
||||||
|
if (c) {
|
||||||
|
s += " ha=";
|
||||||
|
s += c;
|
||||||
|
}
|
||||||
|
c = valign2code (valign ());
|
||||||
|
if (c) {
|
||||||
|
s += " va=";
|
||||||
|
s += c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template class DB_PUBLIC text<Coord>;
|
||||||
|
template class DB_PUBLIC text<DCoord>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace tl
|
namespace tl
|
||||||
{
|
{
|
||||||
|
|
||||||
template<> void extractor_impl (tl::Extractor &ex, db::Text &p)
|
template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Text &p)
|
||||||
{
|
{
|
||||||
if (! test_extractor_impl (ex, p)) {
|
if (! test_extractor_impl (ex, p)) {
|
||||||
ex.error (tl::to_string (tr ("Expected a text specification")));
|
ex.error (tl::to_string (tr ("Expected a text specification")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void extractor_impl (tl::Extractor &ex, db::DText &p)
|
template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DText &p)
|
||||||
{
|
{
|
||||||
if (! test_extractor_impl (ex, p)) {
|
if (! test_extractor_impl (ex, p)) {
|
||||||
ex.error (tl::to_string (tr ("Expected a text specification")));
|
ex.error (tl::to_string (tr ("Expected a text specification")));
|
||||||
|
|
@ -69,6 +160,28 @@ template<class C> bool _test_extractor_impl (tl::Extractor &ex, db::text<C> &t)
|
||||||
|
|
||||||
ex.expect (")");
|
ex.expect (")");
|
||||||
|
|
||||||
|
if (ex.test ("s=")) {
|
||||||
|
C size = 0;
|
||||||
|
ex.read (size);
|
||||||
|
t.size (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ex.test ("f=")) {
|
||||||
|
int font = -1;
|
||||||
|
ex.read (font);
|
||||||
|
t.font (db::Font (font));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ex.test ("ha=")) {
|
||||||
|
db::HAlign ha = db::extract_halign (ex);
|
||||||
|
t.halign (ha);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ex.test ("va=")) {
|
||||||
|
db::VAlign va = db::extract_valign (ex);
|
||||||
|
t.valign (va);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -76,12 +189,12 @@ template<class C> bool _test_extractor_impl (tl::Extractor &ex, db::text<C> &t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> bool test_extractor_impl (tl::Extractor &ex, db::Text &p)
|
template<> DB_PUBLIC bool test_extractor_impl (tl::Extractor &ex, db::Text &p)
|
||||||
{
|
{
|
||||||
return _test_extractor_impl (ex, p);
|
return _test_extractor_impl (ex, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> bool test_extractor_impl (tl::Extractor &ex, db::DText &p)
|
template<> DB_PUBLIC bool test_extractor_impl (tl::Extractor &ex, db::DText &p)
|
||||||
{
|
{
|
||||||
return _test_extractor_impl (ex, p);
|
return _test_extractor_impl (ex, p);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -757,10 +757,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* @brief String conversion
|
* @brief String conversion
|
||||||
*/
|
*/
|
||||||
std::string to_string (double dbu = 0.0) const
|
std::string to_string (double dbu = 0.0) const;
|
||||||
{
|
|
||||||
return std::string ("(") + tl::to_quoted_string (string ()) + "," + m_trans.to_string (dbu) + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reduce the text
|
* @brief Reduce the text
|
||||||
|
|
|
||||||
|
|
@ -1167,7 +1167,7 @@ TEST(5)
|
||||||
EXPECT_EQ (r.text (),
|
EXPECT_EQ (r.text (),
|
||||||
"layout_diff: texts differ for layer 17/0 in cell c2x\n"
|
"layout_diff: texts differ for layer 17/0 in cell c2x\n"
|
||||||
"Not in b but in a:\n"
|
"Not in b but in a:\n"
|
||||||
" ('X',r90 2,3)\n"
|
" ('X',r90 2,3) s=17\n"
|
||||||
"Not in a but in b:\n"
|
"Not in a but in b:\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -1198,10 +1198,10 @@ TEST(5)
|
||||||
"layout_diff: texts differ for layer 17/0 in cell c2x\n"
|
"layout_diff: texts differ for layer 17/0 in cell c2x\n"
|
||||||
"Not in b but in a:\n"
|
"Not in b but in a:\n"
|
||||||
"Not in a but in b:\n"
|
"Not in a but in b:\n"
|
||||||
" ('X',r90 2,3)\n"
|
" ('X',r90 2,3) s=18\n"
|
||||||
" ('Y',r90 2,3)\n"
|
" ('Y',r90 2,3) s=17\n"
|
||||||
" ('X',r90 3,4)\n"
|
" ('X',r90 3,4) s=17\n"
|
||||||
" ('X',r180 2,3)\n"
|
" ('X',r180 2,3) s=17\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
// two more to match more of h:
|
// two more to match more of h:
|
||||||
|
|
@ -1216,8 +1216,8 @@ TEST(5)
|
||||||
"layout_diff: texts differ for layer 17/0 in cell c2x\n"
|
"layout_diff: texts differ for layer 17/0 in cell c2x\n"
|
||||||
"Not in b but in a:\n"
|
"Not in b but in a:\n"
|
||||||
"Not in a but in b:\n"
|
"Not in a but in b:\n"
|
||||||
" ('Y',r90 2,3)\n"
|
" ('Y',r90 2,3) s=17\n"
|
||||||
" ('X',r180 2,3)\n"
|
" ('X',r180 2,3) s=17\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,4 +133,68 @@ TEST(3)
|
||||||
EXPECT_EQ (std::string (s2b.text_string ()), "U");
|
EXPECT_EQ (std::string (s2b.text_string ()), "U");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string string_trip (const db::Text &t)
|
||||||
|
{
|
||||||
|
std::string s = t.to_string ();
|
||||||
|
tl::Extractor ex (s.c_str ());
|
||||||
|
|
||||||
|
db::Text t2;
|
||||||
|
ex.read (t2);
|
||||||
|
|
||||||
|
return t2.to_string ();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(4)
|
||||||
|
{
|
||||||
|
db::Text t ("abc", db::Trans (db::Trans::r90));
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0)");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.size (150);
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0) s=150");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.size (0);
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0)");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.halign (db::HAlignCenter);
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0) ha=c");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.halign (db::HAlignLeft);
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0) ha=l");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.halign (db::HAlignRight);
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0) ha=r");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.valign (db::VAlignCenter);
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0) ha=r va=c");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.valign (db::VAlignTop);
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0) ha=r va=t");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.valign (db::VAlignBottom);
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0) ha=r va=b");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
|
||||||
|
t.halign (db::NoHAlign);
|
||||||
|
t.valign (db::NoVAlign);
|
||||||
|
t.font (db::Font (17));
|
||||||
|
|
||||||
|
EXPECT_EQ (t.to_string (), "('abc',r90 0,0) f=17");
|
||||||
|
EXPECT_EQ (string_trip (t), t.to_string ());
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1102,7 +1102,7 @@ class DBShapes_TestClass < TestBase
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
shapes.each( RBA::Shapes::SAll ) { |s| arr.push( s.to_s ) }
|
shapes.each( RBA::Shapes::SAll ) { |s| arr.push( s.to_s ) }
|
||||||
assert_equal( arr, ["edge (1,2;3,4)", "text ('text',r0 100,200)", "text ('blabla',m0 100,200) prop_id=1"] )
|
assert_equal( arr, ["edge (1,2;3,4)", "text ('text',r0 100,200)", "text ('blabla',m0 100,200) f=3 ha=c va=b prop_id=1"] )
|
||||||
|
|
||||||
assert_equal( s1.is_valid?, true )
|
assert_equal( s1.is_valid?, true )
|
||||||
assert_equal( s1.shapes.is_valid?(s1), true )
|
assert_equal( s1.shapes.is_valid?(s1), true )
|
||||||
|
|
@ -1316,7 +1316,7 @@ class DBShapes_TestClass < TestBase
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
shapes.each( RBA::Shapes::SAll ) { |s| arr.push( s.to_s ) }
|
shapes.each( RBA::Shapes::SAll ) { |s| arr.push( s.to_s ) }
|
||||||
assert_equal( arr, ["edge (1,2;3,4)", "text ('text',r0 100,200)", "text ('blabla',m0 100,200) prop_id=1"] )
|
assert_equal( arr, ["edge (1,2;3,4)", "text ('text',r0 100,200)", "text ('blabla',m0 100,200) f=3 ha=c va=b prop_id=1"] )
|
||||||
|
|
||||||
assert_equal( s1.is_valid?, true )
|
assert_equal( s1.is_valid?, true )
|
||||||
assert_equal( s1.shapes.is_valid?(s1), true )
|
assert_equal( s1.shapes.is_valid?(s1), true )
|
||||||
|
|
|
||||||
|
|
@ -102,20 +102,20 @@ class DBText_TestClass < TestBase
|
||||||
|
|
||||||
b = a.dup
|
b = a.dup
|
||||||
|
|
||||||
assert_equal( a.moved( RBA::DPoint::new( 0, 1 ) ).to_s, "('hallo',m45 5,8)" )
|
assert_equal( a.moved( RBA::DPoint::new( 0, 1 ) ).to_s, "('hallo',m45 5,8) s=23 f=8 ha=r va=b" )
|
||||||
a.move( RBA::DPoint::new( 1, 0 ) )
|
a.move( RBA::DPoint::new( 1, 0 ) )
|
||||||
assert_equal( a.to_s, "('hallo',m45 6,7)" )
|
assert_equal( a.to_s, "('hallo',m45 6,7) s=23 f=8 ha=r va=b" )
|
||||||
|
|
||||||
b = b.transformed( RBA::DTrans::new( RBA::DTrans::R0, RBA::DPoint::new( 1, 0 )) )
|
b = b.transformed( RBA::DTrans::new( RBA::DTrans::R0, RBA::DPoint::new( 1, 0 )) )
|
||||||
assert_equal( b.to_s, "('hallo',m45 6,7)" )
|
assert_equal( b.to_s, "('hallo',m45 6,7) s=23 f=8 ha=r va=b" )
|
||||||
|
|
||||||
m = RBA::DCplxTrans::new( RBA::DTrans::new, 1.5 )
|
m = RBA::DCplxTrans::new( RBA::DTrans::new, 1.5 )
|
||||||
assert_equal( a.transformed(m).class.to_s, "RBA::DText" )
|
assert_equal( a.transformed(m).class.to_s, "RBA::DText" )
|
||||||
assert_equal( a.transformed(m).to_s, "('hallo',m45 9,10.5)" )
|
assert_equal( a.transformed(m).to_s, "('hallo',m45 9,10.5) s=34.5 f=8 ha=r va=b" )
|
||||||
|
|
||||||
m = RBA::VCplxTrans::new( 1000.0 )
|
m = RBA::VCplxTrans::new( 1000.0 )
|
||||||
assert_equal( a.transformed(m).class.to_s, "RBA::Text" )
|
assert_equal( a.transformed(m).class.to_s, "RBA::Text" )
|
||||||
assert_equal( a.transformed(m).to_s, "('hallo',m45 6000,7000)" )
|
assert_equal( a.transformed(m).to_s, "('hallo',m45 6000,7000) s=23000 f=8 ha=r va=b" )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -196,16 +196,16 @@ class DBText_TestClass < TestBase
|
||||||
|
|
||||||
b = a.dup
|
b = a.dup
|
||||||
|
|
||||||
assert_equal( a.moved( RBA::Point::new( 0, 1 ) ).to_s, "('hallo',m45 5,8)" )
|
assert_equal( a.moved( RBA::Point::new( 0, 1 ) ).to_s, "('hallo',m45 5,8) s=23 f=8 ha=l va=t" )
|
||||||
a.move( RBA::Point::new( 1, 0 ) )
|
a.move( RBA::Point::new( 1, 0 ) )
|
||||||
assert_equal( a.to_s, "('hallo',m45 6,7)" )
|
assert_equal( a.to_s, "('hallo',m45 6,7) s=23 f=8 ha=l va=t" )
|
||||||
|
|
||||||
b = b.transformed( RBA::Trans::new( RBA::Trans::R0, RBA::Point::new( 1, 0 )) )
|
b = b.transformed( RBA::Trans::new( RBA::Trans::R0, RBA::Point::new( 1, 0 )) )
|
||||||
assert_equal( b.to_s, "('hallo',m45 6,7)" )
|
assert_equal( b.to_s, "('hallo',m45 6,7) s=23 f=8 ha=l va=t" )
|
||||||
|
|
||||||
m = RBA::CplxTrans::new( RBA::Trans::new, 1.5 )
|
m = RBA::CplxTrans::new( RBA::Trans::new, 1.5 )
|
||||||
assert_equal( a.transformed(m).to_s, "('hallo',m45 9,10.5)" )
|
assert_equal( a.transformed(m).to_s, "('hallo',m45 9,10.5) s=34.5 f=8 ha=l va=t" )
|
||||||
assert_equal( a.transformed(RBA::ICplxTrans::new(m)).to_s, "('hallo',m45 9,11)" )
|
assert_equal( a.transformed(RBA::ICplxTrans::new(m)).to_s, "('hallo',m45 9,11) s=35 f=8 ha=l va=t" )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue