diff --git a/src/edt/edt/edtPartialService.cc b/src/edt/edt/edtPartialService.cc index 917122572..cf0f1ca4f 100644 --- a/src/edt/edt/edtPartialService.cc +++ b/src/edt/edt/edtPartialService.cc @@ -2288,7 +2288,7 @@ bool PartialService::key_event (unsigned int key, unsigned int buttons) { if (m_moving && buttons == 0 && (key == lay::KeyEnter || key == lay::KeyReturn)) { - mp_view->move_service ()->end_move (); + mp_view->move_service ()->finish_move (); return true; } else { return false; diff --git a/src/laybasic/laybasic/layBitmapRenderer.cc b/src/laybasic/laybasic/layBitmapRenderer.cc index 9236b43ee..0065f836b 100644 --- a/src/laybasic/laybasic/layBitmapRenderer.cc +++ b/src/laybasic/laybasic/layBitmapRenderer.cc @@ -389,9 +389,13 @@ BitmapRenderer::draw (const db::Shape &shape, const db::CplxTrans &trans, db::DCoord h = trans.mag () * m_default_text_size; db::Font font = shape.text_font () == db::NoFont ? m_font : shape.text_font (); - if (m_apply_text_trans && font != db::NoFont && font != db::DefaultFont) { - fp = db::DFTrans (trans.fp_trans () * shape.text_trans ()); - h = trans.mag () * (shape.text_size () > 0 ? shape.text_size () : m_default_text_size); + if (font != db::NoFont && font != db::DefaultFont) { + if ((m_apply_text_trans_mode & 2) != 0) { + fp = db::DFTrans (trans.fp_trans () * shape.text_trans ()); + } + if ((m_apply_text_trans_mode & 1) != 0) { + h = trans.mag () * (shape.text_size () > 0 ? shape.text_size () : m_default_text_size); + } } db::HAlign halign = shape.text_halign (); @@ -1090,9 +1094,13 @@ BitmapRenderer::draw (const db::Text &txt, const db::CplxTrans &trans, db::DCoord h = trans.mag () * m_default_text_size; db::Font font = txt.font () == db::NoFont ? m_font : txt.font (); - if (m_apply_text_trans && font != db::NoFont && font != db::DefaultFont) { - fp = db::DFTrans (trans.fp_trans () * txt.trans ()); - h = trans.mag () * (txt.size () > 0 ? txt.size () : m_default_text_size); + if (font != db::NoFont && font != db::DefaultFont) { + if ((m_apply_text_trans_mode & 2) != 0) { + fp = db::DFTrans (trans.fp_trans () * txt.trans ()); + } + if ((m_apply_text_trans_mode & 1) != 0) { + h = trans.mag () * (txt.size () > 0 ? txt.size () : m_default_text_size); + } } double fy = 0.0; @@ -1161,9 +1169,13 @@ BitmapRenderer::draw (const db::DText &txt, const db::DCplxTrans &trans, db::DCoord h = trans.ctrans (m_default_text_size_dbl); db::Font font = txt.font () == db::NoFont ? m_font : txt.font (); - if (m_apply_text_trans && font != db::NoFont && font != db::DefaultFont) { - fp = trans.fp_trans () * db::DFTrans (txt.trans ()); - h = trans.ctrans (txt.size () > 0 ? txt.size () : m_default_text_size_dbl); + if (font != db::NoFont && font != db::DefaultFont) { + if ((m_apply_text_trans_mode & 2) != 0) { + fp = trans.fp_trans () * db::DFTrans (txt.trans ()); + } + if ((m_apply_text_trans_mode & 1) != 0) { + h = trans.ctrans (txt.size () > 0 ? txt.size () : m_default_text_size_dbl); + } } double fy = 0.0; diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index b0c537a40..5c8333fd0 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -351,6 +351,7 @@ LayoutViewBase::init (db::Manager *mgr) m_bitmap_caching = true; m_show_properties = false; m_apply_text_trans = true; + m_apply_text_trans_mode = 3; m_default_text_size = 0.1; m_text_point_mode = false; m_text_font = 0; @@ -1029,6 +1030,13 @@ LayoutViewBase::configure (const std::string &name, const std::string &value) apply_text_trans (flag); return true; + } else if (name == cfg_apply_text_trans_mode) { + + unsigned int mode; + tl::from_string (value, mode); + apply_text_trans_mode (mode); + return true; + } else if (name == cfg_markers_visible) { bool flag; @@ -5541,7 +5549,16 @@ LayoutViewBase::apply_text_trans (bool f) } } -void +void +LayoutViewBase::apply_text_trans_mode (unsigned int m) +{ + if (m_apply_text_trans_mode != m) { + m_apply_text_trans_mode = m; + redraw (); + } +} + +void LayoutViewBase::offset_stipples (bool f) { if (m_stipple_offset != f) { diff --git a/src/laybasic/laybasic/layLayoutViewBase.h b/src/laybasic/laybasic/layLayoutViewBase.h index eaa83b818..e1f946503 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.h +++ b/src/laybasic/laybasic/layLayoutViewBase.h @@ -1400,6 +1400,26 @@ public: return m_apply_text_trans; } + /** + * @brief Sets the mode how to apply the text transformation + * + * The mode value has two bits: + * - bit 0: apply scaling + * - bit 1: apply rotation + * + * The default is mode "3" (scaling and rotation). + * The mode is effective only if "apply_text_trans" is true. + */ + void apply_text_trans_mode (unsigned int m); + + /** + * @brief Gets the mode how to apply the text transformation + */ + unsigned int apply_text_trans_mode () const + { + return m_apply_text_trans ? m_apply_text_trans_mode : 0; + } + /** * @brief Text object color */ @@ -3074,6 +3094,7 @@ private: bool m_show_properties; tl::Color m_text_color; bool m_apply_text_trans; + unsigned int m_apply_text_trans_mode; double m_default_text_size; bool m_text_point_mode; unsigned int m_text_font; diff --git a/src/laybasic/laybasic/layLayoutViewConfig.cc b/src/laybasic/laybasic/layLayoutViewConfig.cc index dd65bad15..e0ecd9fa7 100644 --- a/src/laybasic/laybasic/layLayoutViewConfig.cc +++ b/src/laybasic/laybasic/layLayoutViewConfig.cc @@ -67,6 +67,7 @@ public: options.push_back (std::pair (cfg_bitmap_caching, "true")); options.push_back (std::pair (cfg_show_properties, "false")); options.push_back (std::pair (cfg_apply_text_trans, "true")); + options.push_back (std::pair (cfg_apply_text_trans_mode, "3")); options.push_back (std::pair (cfg_global_trans, "r0")); options.push_back (std::pair (cfg_default_text_size, "0.1")); options.push_back (std::pair (cfg_text_point_mode, "false")); diff --git a/src/laybasic/laybasic/layMarker.cc b/src/laybasic/laybasic/layMarker.cc index f30d1387f..ef3172f2b 100644 --- a/src/laybasic/laybasic/layMarker.cc +++ b/src/laybasic/laybasic/layMarker.cc @@ -640,7 +640,7 @@ ShapeMarker::render (const Viewport &vp, ViewObjectCanvas &canvas) lay::Renderer &r = canvas.renderer (); r.set_font (db::Font (view ()->text_font ())); - r.apply_text_trans (view ()->apply_text_trans ()); + r.apply_text_trans_mode (view ()->apply_text_trans_mode ()); r.default_text_size (view ()->default_text_size () / ly->dbu ()); r.set_precise (true); @@ -1171,7 +1171,7 @@ Marker::render (const Viewport &vp, ViewObjectCanvas &canvas) lay::Renderer &r = canvas.renderer (); r.set_font (db::Font (view ()->text_font ())); - r.apply_text_trans (view ()->apply_text_trans ()); + r.apply_text_trans_mode (view ()->apply_text_trans_mode ()); r.default_text_size (view ()->default_text_size () / dbu ()); r.set_precise (true); @@ -1319,7 +1319,7 @@ DMarker::render (const Viewport &vp, ViewObjectCanvas &canvas) lay::Renderer &r = canvas.renderer (); r.set_font (db::Font (view ()->text_font ())); - r.apply_text_trans (view ()->apply_text_trans ()); + r.apply_text_trans_mode (view ()->apply_text_trans_mode ()); r.default_text_size_dbl (view ()->default_text_size ()); r.set_precise (true); diff --git a/src/laybasic/laybasic/layMove.cc b/src/laybasic/laybasic/layMove.cc index a93639741..b23f7c3bc 100644 --- a/src/laybasic/laybasic/layMove.cc +++ b/src/laybasic/laybasic/layMove.cc @@ -118,7 +118,7 @@ MoveService::key_event (unsigned int key, unsigned int buttons) } if (buttons == 0 && (key == lay::KeyEnter || key == lay::KeyReturn)) { - end_move (); + finish_move (); return true; } @@ -378,7 +378,7 @@ MoveService::start_move (db::Transaction *transaction, bool transient_selection) } void -MoveService::end_move () +MoveService::finish_move () { if (m_dragging) { handle_click (m_mouse_pos, 0, false, 0); diff --git a/src/laybasic/laybasic/layMove.h b/src/laybasic/laybasic/layMove.h index b49c3f455..fc7b4cedb 100644 --- a/src/laybasic/laybasic/layMove.h +++ b/src/laybasic/laybasic/layMove.h @@ -45,7 +45,7 @@ public: ~MoveService (); bool start_move (db::Transaction *transaction = 0, bool transient_selection = false); - void end_move (); + void finish_move (); bool configure (const std::string &name, const std::string &value); void function (const std::string &name, const std::string &value); diff --git a/src/laybasic/laybasic/layRedrawThreadWorker.cc b/src/laybasic/laybasic/layRedrawThreadWorker.cc index f193fa1cd..33de7a2da 100644 --- a/src/laybasic/laybasic/layRedrawThreadWorker.cc +++ b/src/laybasic/laybasic/layRedrawThreadWorker.cc @@ -151,7 +151,7 @@ RedrawThreadWorker::RedrawThreadWorker (RedrawThread *redraw_thread) m_text_lazy_rendering = false; m_bitmap_caching = false; m_show_properties = false; - m_apply_text_trans = false; + m_apply_text_trans_mode = 0; m_default_text_size = 0.0; m_drop_small_cells = false; m_drop_small_cells_value = 0; @@ -291,7 +291,7 @@ RedrawThreadWorker::perform_task (tl::Task *task) mp_renderer->draw_description_property (false); mp_renderer->default_text_size (m_default_text_size / mp_layout->dbu ()); mp_renderer->set_font (db::Font (m_text_font)); - mp_renderer->apply_text_trans (m_apply_text_trans); + mp_renderer->apply_text_trans_mode (m_apply_text_trans_mode); for (std::vector::const_iterator t = li.trans.begin (); t != li.trans.end (); ++t) { db::CplxTrans trans = m_vp_trans * *t * db::CplxTrans (mp_layout->dbu ()); @@ -533,7 +533,7 @@ RedrawThreadWorker::perform_task (tl::Task *task) mp_renderer->draw_description_property (true); mp_renderer->default_text_size (db::Coord (m_default_text_size / mp_layout->dbu ())); mp_renderer->set_font (db::Font (m_text_font)); - mp_renderer->apply_text_trans (m_apply_text_trans); + mp_renderer->apply_text_trans_mode (m_apply_text_trans_mode); bool f = m_text_lazy_rendering; @@ -693,7 +693,7 @@ RedrawThreadWorker::setup (LayoutViewBase *view, RedrawThreadCanvas *canvas, con m_text_lazy_rendering = view->text_lazy_rendering (); m_bitmap_caching = view->bitmap_caching (); m_show_properties = view->show_properties_as_text (); - m_apply_text_trans = view->apply_text_trans (); + m_apply_text_trans_mode = view->apply_text_trans_mode (); m_default_text_size = view->default_text_size (); m_drop_small_cells = view->drop_small_cells (); m_drop_small_cells_value = view->drop_small_cells_value (); diff --git a/src/laybasic/laybasic/layRedrawThreadWorker.h b/src/laybasic/laybasic/layRedrawThreadWorker.h index 936131a24..ea5b12c85 100644 --- a/src/laybasic/laybasic/layRedrawThreadWorker.h +++ b/src/laybasic/laybasic/layRedrawThreadWorker.h @@ -224,7 +224,7 @@ private: bool m_text_lazy_rendering; bool m_bitmap_caching; bool m_show_properties; - bool m_apply_text_trans; + unsigned int m_apply_text_trans_mode; double m_default_text_size; bool m_drop_small_cells; unsigned int m_drop_small_cells_value; diff --git a/src/laybasic/laybasic/layRenderer.cc b/src/laybasic/laybasic/layRenderer.cc index dbee023f6..c6882df18 100644 --- a/src/laybasic/laybasic/layRenderer.cc +++ b/src/laybasic/laybasic/layRenderer.cc @@ -42,7 +42,7 @@ Renderer::Renderer (unsigned int width, unsigned int height, double resolution, m_draw_description_property (false), m_default_text_size (1000), m_default_text_size_dbl (1.0), - m_apply_text_trans (true), + m_apply_text_trans_mode (3), m_precise (false), m_xfill (false), m_font (db::DefaultFont), diff --git a/src/laybasic/laybasic/layRenderer.h b/src/laybasic/laybasic/layRenderer.h index b427c370c..0c9665080 100644 --- a/src/laybasic/laybasic/layRenderer.h +++ b/src/laybasic/laybasic/layRenderer.h @@ -164,19 +164,23 @@ public: } /** - * @brief Apply text transformations to text or not for draw(db::Text..). + * @brief How to apply text transformations for draw(db::Text..). + * + * This is a bit field: + * - bit 0: apply scaling + * - bit 1: apply rotation */ - void apply_text_trans (bool f) + void apply_text_trans_mode (unsigned int m) { - m_apply_text_trans = f; + m_apply_text_trans_mode = m; } /** - * @brief Get the flag which determines to apply text transformations for draw(db::Text..) + * @brief Get the value indicating how to apply text transformation for draw(db::Text..). */ - bool apply_text_trans () const + unsigned int apply_text_trans_mode () const { - return m_apply_text_trans; + return m_apply_text_trans_mode; } /** @@ -415,7 +419,7 @@ protected: bool m_draw_description_property; db::DCoord m_default_text_size; double m_default_text_size_dbl; - bool m_apply_text_trans; + unsigned int m_apply_text_trans_mode; bool m_precise; bool m_xfill; db::Font m_font; diff --git a/src/laybasic/laybasic/layTextInfo.cc b/src/laybasic/laybasic/layTextInfo.cc index e24ea03c0..b93fea985 100644 --- a/src/laybasic/laybasic/layTextInfo.cc +++ b/src/laybasic/laybasic/layTextInfo.cc @@ -32,7 +32,7 @@ namespace lay TextInfo::TextInfo (const LayoutViewBase *view) : m_default_text_size (view->default_text_size ()), m_default_font (db::Font (view->text_font ())), - m_apply_text_trans (view->apply_text_trans ()), + m_apply_text_trans_mode (view->apply_text_trans_mode ()), m_resolution (view->canvas ()->font_resolution ()), m_point_mode (view->text_point_mode ()) { @@ -49,14 +49,18 @@ TextInfo::bbox (const db::DText &text, const db::DCplxTrans &vp_trans) const // offset in pixels (space between origin and text) const double offset = 2.0 / vp_trans.mag (); - db::DTrans tt = text.trans (); + db::DTrans tt; db::DCoord h; db::Font font = text.font () == db::NoFont ? m_default_font : text.font (); - if (m_apply_text_trans && font != db::NoFont && font != db::DefaultFont) { + if ((m_apply_text_trans_mode & 2) != 0 && font != db::NoFont && font != db::DefaultFont) { + tt = text.trans (); + } else { + tt = db::DTrans (vp_trans.fp_trans ().inverted ().angle (), text.trans ().disp ()); + } + if (((m_apply_text_trans_mode & 1) != 0) && font != db::NoFont && font != db::DefaultFont) { h = text.size () > 0 ? text.size () : m_default_text_size; } else { - tt = db::DTrans (vp_trans.fp_trans ().inverted ().angle (), tt.disp ()); h = m_default_text_size; } diff --git a/src/laybasic/laybasic/layTextInfo.h b/src/laybasic/laybasic/layTextInfo.h index 0c594a205..a04f63a56 100644 --- a/src/laybasic/laybasic/layTextInfo.h +++ b/src/laybasic/laybasic/layTextInfo.h @@ -74,7 +74,7 @@ public: private: double m_default_text_size; db::Font m_default_font; - bool m_apply_text_trans; + unsigned int m_apply_text_trans_mode; double m_resolution; bool m_point_mode; }; diff --git a/src/laybasic/laybasic/laybasicConfig.h b/src/laybasic/laybasic/laybasicConfig.h index f3b6b2c03..5ace619a0 100644 --- a/src/laybasic/laybasic/laybasicConfig.h +++ b/src/laybasic/laybasic/laybasicConfig.h @@ -103,6 +103,7 @@ static const std::string cfg_text_lazy_rendering ("text-lazy-rendering"); static const std::string cfg_bitmap_caching ("bitmap-caching"); static const std::string cfg_show_properties ("show-properties"); static const std::string cfg_apply_text_trans ("apply-text-trans"); +static const std::string cfg_apply_text_trans_mode ("apply-text-trans-mode"); static const std::string cfg_global_trans ("global-trans"); static const std::string cfg_no_stipple ("no-stipple"); static const std::string cfg_stipple_offset ("stipple-offset"); diff --git a/src/laybasic/unit_tests/layTextInfoTests.cc b/src/laybasic/unit_tests/layTextInfoTests.cc index 99a471c82..a0613f2db 100644 --- a/src/laybasic/unit_tests/layTextInfoTests.cc +++ b/src/laybasic/unit_tests/layTextInfoTests.cc @@ -123,4 +123,25 @@ TEST(1) EXPECT_EQ (ti.bbox (text, db::DCplxTrans ()).to_string (), "(12,20.6;24,27)"); EXPECT_EQ (ti.bbox (text, db::DCplxTrans (2.0)).to_string (), "(11,19.6;23,26)"); EXPECT_EQ (ti.bbox (text, db::DCplxTrans (db::DFTrans (1))).to_string (), "(10.6,6;17,18)"); + + // apply_text_trans = true, scale only + lv.apply_text_trans (true); + lv.apply_text_trans_mode (1); + ti = lay::TextInfo (&lv); + EXPECT_EQ (ti.bbox (text3, db::DCplxTrans ()).to_string (), "(12,15;134,83)"); + // with apply_text_trans_mode not including rotation, the global transformation does change the text + // bounding box. + EXPECT_EQ (ti.bbox (text, db::DCplxTrans ()).to_string (), "(12,20.6;24,27)"); + EXPECT_EQ (ti.bbox (text, db::DCplxTrans (2.0)).to_string (), "(11,19.6;23,26)"); + EXPECT_EQ (ti.bbox (text, db::DCplxTrans (db::DFTrans (1))).to_string (), "(10.6,6;17,18)"); + + // apply_text_trans = true, rotation only + lv.apply_text_trans (true); + lv.apply_text_trans_mode (2); + ti = lay::TextInfo (&lv); + EXPECT_EQ (ti.bbox (text3, db::DCplxTrans ()).to_string (), "(-4.2,22;9.4,46.4)"); + // with apply_text_trans including rotation, the global transformation changes the text bounding box + EXPECT_EQ (ti.bbox (text, db::DCplxTrans ()).to_string (), "(12,20.6;24,27)"); + EXPECT_EQ (ti.bbox (text, db::DCplxTrans (2.0)).to_string (), "(11,19.6;23,26)"); + EXPECT_EQ (ti.bbox (text, db::DCplxTrans (db::DFTrans (1))).to_string (), "(12,20.6;24,27)"); } diff --git a/src/layui/layui/LayoutViewConfigPage2b.ui b/src/layui/layui/LayoutViewConfigPage2b.ui index 45824dc69..5d0ce4142 100644 --- a/src/layui/layui/LayoutViewConfigPage2b.ui +++ b/src/layui/layui/LayoutViewConfigPage2b.ui @@ -1,7 +1,8 @@ - + + LayoutViewConfigPage2b - - + + 0 0 @@ -9,57 +10,55 @@ 276 - + Settings - - + + 9 - + 6 - - - + + + Show texts or properties - + true - - + + 9 - + 6 - - - + + + QFrame::NoFrame - + QFrame::Raised - - - 0 - - + + 6 + + 0 + - - - - 0 - 0 + + + 0 0 - + 0 0 @@ -68,26 +67,24 @@ - - - - 0 - 0 + + + 0 0 - + micron - + Qt::Horizontal - + 40 20 @@ -98,34 +95,34 @@ - - - + + + QFrame::NoFrame - + QFrame::Raised - - - 0 - - + + 6 + + 0 + - - + + - + Qt::Horizontal - + 40 20 @@ -136,30 +133,30 @@ - - - + + + QFrame::NoFrame - + QFrame::Raised - - - 0 - - + + 6 + + 0 + - + - + Qt::Horizontal - + 40 20 @@ -170,15 +167,15 @@ - + - + Qt::Vertical - + QSizePolicy::Fixed - + 561 16 @@ -186,47 +183,54 @@ - - - - Apply text scaling and rotation (not available for "Default" font) + + + + Apply text scaling (not available for "Default" font) - - - + + + Show properties also - - - + + + Color - - - + + + Standard text size - - - + + + Text font + + + + Apply text rotation (not available for "Default" font) + + + - + lay::ColorButton @@ -237,9 +241,10 @@ text_group text_font_cb - text_apply_trans_cbx - text_def_size_edit text_color_pb + text_def_size_edit + text_apply_trans_scale_cbx + text_apply_trans_rotate_cbx show_properties_cbx diff --git a/src/layui/layui/layLayoutViewConfigPages.cc b/src/layui/layui/layLayoutViewConfigPages.cc index ac6ecfe7f..3d353eb94 100644 --- a/src/layui/layui/layLayoutViewConfigPages.cc +++ b/src/layui/layui/layLayoutViewConfigPages.cc @@ -300,7 +300,15 @@ LayoutViewConfigPage2b::setup (lay::Dispatcher *root) bool flag = false; root->config_get (cfg_apply_text_trans, flag); - mp_ui->text_apply_trans_cbx->setChecked (flag); + + unsigned int mode = 0; + if (flag) { + mode = 3; + root->config_get (cfg_apply_text_trans_mode, mode); + } + + mp_ui->text_apply_trans_scale_cbx->setChecked ((mode & 1) != 0); + mp_ui->text_apply_trans_rotate_cbx->setChecked ((mode & 2) != 0); root->config_get (cfg_text_visible, flag); mp_ui->text_group->setChecked (flag); @@ -327,8 +335,11 @@ LayoutViewConfigPage2b::setup (lay::Dispatcher *root) void LayoutViewConfigPage2b::commit (lay::Dispatcher *root) { + unsigned int mode = (mp_ui->text_apply_trans_scale_cbx->isChecked () ? 1 : 0) | (mp_ui->text_apply_trans_rotate_cbx->isChecked () ? 2 : 0); + root->config_set (cfg_apply_text_trans, mode != 0); // for backward compatibility before version 0.30.8 + root->config_set (cfg_apply_text_trans_mode, mode); + root->config_set (cfg_text_color, mp_ui->text_color_pb->get_color (), ColorConverter ()); - root->config_set (cfg_apply_text_trans, mp_ui->text_apply_trans_cbx->isChecked ()); root->config_set (cfg_text_visible, mp_ui->text_group->isChecked ()); root->config_set (cfg_show_properties, mp_ui->show_properties_cbx->isChecked ()); root->config_set (cfg_text_font, mp_ui->text_font_cb->currentIndex ());