lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 9e39e04 2/3: Refactor for clarity


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 9e39e04 2/3: Refactor for clarity
Date: Sun, 19 Aug 2018 11:09:23 -0400 (EDT)

branch: master
commit 9e39e04afba890d20ed2bcc19f72886dc5b5a998
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Refactor for clarity
    
    Passed actual total margin instead of half the total. Now the margin
    argument means the space between columns on an illustration, where all
    columns are inelastic and right-aligned anyway. This code was originally
    written with group quotes in mind, where all columns but one are
    centered, and margins were therefore bilateral--one em on each side:
      emspace data emspace
    However, for illustrations, there is no marginal space on the right:
      case oe_right:
        x_text += ci.col_width() - dc().GetTextExtent(s).x;
        dc_.DrawText(s, x_text, y_text);
    thus:
      emspace emspace data
    and it is more natural to think of the two-em space between columns as
    the "margin".
---
 report_table.cpp       |  7 ++++++-
 report_table.hpp       |  2 +-
 report_table_test.cpp  | 20 ++++++++++----------
 wx_table_generator.cpp |  4 ++--
 4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/report_table.cpp b/report_table.cpp
index a93f430..69657a1 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -104,15 +104,20 @@ std::vector<int> apportion(std::vector<int> const& votes, 
int total_seats)
 
 void set_column_widths
     (int                             total_width
-    ,int const                       column_margin
+    ,int                             double_margin
     ,std::vector<table_column_info>& all_columns
     )
 //
 // total_width    max table width (page width - page margins)
+// double_margin  total left + right margin
 // column_margin  spacing on both left and right of column
 // all_columns    std::vector<table_column_info>
 //   table_column_info::col_width_ is the only member changed
 {
+    // Use this internally for historical reasons. Formerly, M
+    // was passed, and 2M was used; now, 2M is passed, and what's
+    // used here is 2M/2. This will soon be reimplemented.
+    int const column_margin = double_margin / 2;
     // PDF !! Unconditionally add bilateral margins even though they
     // may conditionally be removed below. This is a questionable
     // design decision; if it is later reversed, then remove the
diff --git a/report_table.hpp b/report_table.hpp
index f89ef5d..e8faa35 100644
--- a/report_table.hpp
+++ b/report_table.hpp
@@ -107,7 +107,7 @@ std::vector<int> LMI_SO apportion(std::vector<int> const& 
votes, int seats);
 
 void LMI_SO set_column_widths
     (int                             total_width
-    ,int                             column_margin
+    ,int                             double_margin
     ,std::vector<table_column_info>& all_columns
     );
 
diff --git a/report_table_test.cpp b/report_table_test.cpp
index 5327a15..3ddc211 100644
--- a/report_table_test.cpp
+++ b/report_table_test.cpp
@@ -175,13 +175,13 @@ void report_table_test::test_generally()
 
     // Width with default margins (12) = maximum available page width.
     v = bloat({1, 2, 3}, {0, 0, 0});
-    set_column_widths(12, 1, v);
+    set_column_widths(12, 2, v);
     expected = {3, 4, 5};
     BOOST_TEST(widths(v) == expected);
 
     // Same columns: same layout, even if page is much wider (99).
     v = bloat({1, 2, 3}, {0, 0, 0});
-    set_column_widths(99, 1, v);
+    set_column_widths(99, 2, v);
     BOOST_TEST(widths(v) == expected);
 
     // Same columns, but inadequate page width.
@@ -208,18 +208,18 @@ void report_table_test::test_generally()
     std::vector<int> actual;
 
     v = bloat({1, 2, 3}, {0, 0, 0});
-    set_column_widths(11, 1, v);
+    set_column_widths(11, 2, v);
     actual = {3, 4, 4};
     BOOST_TEST(widths(v) == actual);
 
     v = bloat({1, 2, 3}, {0, 0, 0});
-    set_column_widths( 6, 1, v);
+    set_column_widths( 6, 2, v);
     actual = {1, 2, 3};
     BOOST_TEST(widths(v) == actual);
 
     // Warning given here:
     v = bloat({1, 2, 3}, {0, 0, 0});
-    set_column_widths( 5, 1, v);
+    set_column_widths( 5, 2, v);
     actual = {3, 4, 5};
     BOOST_TEST(widths(v) == actual);
 
@@ -228,21 +228,21 @@ void report_table_test::test_generally()
     // An elastic column occupies all available space not claimed by
     // inelastic columns...
     v = bloat({1, 2, 0, 3}, {0, 0, 1, 0});
-    set_column_widths(99, 1, v);
+    set_column_widths(99, 2, v);
     expected = {3, 4, (99-12), 5};
     BOOST_TEST(widths(v) == expected);
     // ...though its width might happen to be zero (PDF !! but see
     //   https://lists.nongnu.org/archive/html/lmi/2018-07/msg00049.html
     // which questions whether zero should be allowed):
     v = bloat({1, 2, 0, 3}, {0, 0, 1, 0});
-    set_column_widths(12, 1, v);
+    set_column_widths(12, 2, v);
     expected = {3, 4, 0, 5};
     BOOST_TEST(widths(v) == expected);
 
     // Multiple elastic columns apportion all unclaimed space among
     // themselves.
     v = bloat({1, 2, 0, 3}, {1, 0, 1, 0});
-    set_column_widths(99, 1, v);
+    set_column_widths(99, 2, v);
     expected = {45, 4, 45, 5};
     BOOST_TEST(widths(v) == expected);
 }
@@ -256,7 +256,7 @@ void report_table_test::test_generally()
 void report_table_test::test_group_quote()
 {
     static int const total_width    = 756;
-    static int const default_margin = 7;
+    static int const default_margin = 14;
 
     std::vector<table_column_info> v =
         {{"", 22, oe_center, oe_inelastic}
@@ -288,7 +288,7 @@ void report_table_test::test_group_quote()
 void report_table_test::test_illustration()
 {
     static int const total_width    = 576;
-    static int const default_margin = 7;
+    static int const default_margin = 14;
 
     // Fits with default margin.
 
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index f7c4315..4c3c2ec 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -56,7 +56,7 @@ wx_table_generator::wx_table_generator
         {
         enroll_column(i);
         }
-    set_column_widths(total_width_, one_em_, all_columns_);
+    set_column_widths(total_width_, 2 * one_em_, all_columns_);
 
     // Set a pen with zero width to make grid lines thin,
     // and round cap style so that they combine seamlessly.
@@ -88,7 +88,7 @@ wx_table_generator::wx_table_generator
         {
         enroll_column(i);
         }
-    set_column_widths(total_width_, one_em_, all_columns_);
+    set_column_widths(total_width_, 2 * one_em_, all_columns_);
 
     dc_.SetPen(illustration_rule_color);
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]