@@ -50,49 +50,73 @@ PageLayout::PageLayout(
50
50
// we would get with zero hard margins and MatchSizeMode::M_GROW_MARGINS.
51
51
bool const have_content_box = !unscaled_content_rect.isEmpty ();
52
52
53
- if (have_content_box && (match_size_mode. get () == MatchSizeMode::M_SCALE || match_size_mode. get () == MatchSizeMode::M_AFFINE) )
53
+ if (have_content_box)
54
54
{
55
- // aggregate_size = content_size * scale + margins * width * scale
56
- // Solving for scale:
57
- // scale = aggregate_size / (content_size + margins * width)
58
55
double const agwidth = aggregate_hard_size.width ();
59
56
double const agheight = aggregate_hard_size.height ();
60
- double const aghx = agheight * 0.7071067811865475244 ;
61
- double const agsize = (agwidth < aghx) ? agwidth : aghx;
62
- double const agx = (agwidth - (margins.left () + margins.right ()) * agsize);
63
- double const agy = (agheight - (margins.top () + margins.bottom ()) * agsize);
64
- double const x_scale = (agx > 0.0 ) ? (agx / m_innerRect.width ()) : 1.0 ;
65
- double const y_scale = (agy > 0.0 ) ? (agy / m_innerRect.height ()) : 1.0 ;
66
- if (match_size_mode.get () == MatchSizeMode::M_SCALE)
57
+ double const pagew = m_innerRect.width ();
58
+ double const pageh = m_innerRect.height ();
59
+ double const margins_w = margins.left () + margins.right ();
60
+ double const margins_h = margins.top () + margins.bottom ();
61
+ if ((match_size_mode.get () == MatchSizeMode::M_SCALE) || (match_size_mode.get () == MatchSizeMode::M_AFFINE))
67
62
{
68
- if (x_scale > 1.0 && y_scale > 1.0 )
63
+ double const pagewidthx = pagew;
64
+ double const pagewidthy = pageh * 0.7071067811865475244 ;
65
+ double const pagewidth = (pagewidthx < pagewidthy) ? pagewidthy : pagewidthx;
66
+ double const pagewm = pagew + margins_w * pagewidth;
67
+ double const pagehm = pageh + margins_h * pagewidth;
68
+ if (match_size_mode.get () == MatchSizeMode::M_SCALE)
69
69
{
70
- m_scaleFactor_X = std::min (x_scale, y_scale);
70
+ // aggregate_size = content_size * scale + margins * width * scale
71
+ // Solving for scale:
72
+ // scale = aggregate_size / (content_size + margins * width)
73
+ double const x_scale = (pagewm > 0.0 ) ? (agwidth / pagewm) : 1.0 ;
74
+ double const y_scale = (pagehm > 0.0 ) ? (agheight / pagehm) : 1.0 ;
75
+
76
+ if (x_scale > 1.0 && y_scale > 1.0 )
77
+ {
78
+ m_scaleFactor_X = std::min (x_scale, y_scale);
79
+ }
80
+ else if (x_scale < 1.0 && y_scale < 1.0 )
81
+ {
82
+ m_scaleFactor_X = std::max (x_scale, y_scale);
83
+ }
84
+ m_scaleFactor_Y = m_scaleFactor_X;
71
85
}
72
- else if (x_scale < 1.0 && y_scale < 1.0 )
86
+ else
73
87
{
74
- m_scaleFactor_X = std::max (x_scale, y_scale);
88
+ double const pgx = (pagewm < agwidth) ? agwidth : pagewm;
89
+ double const pgy = (pagehm < agheight) ? agheight : pagehm;
90
+ double const cgx = pgx / (1.0 + margins_w);
91
+ double const cgy = pgy / (1.0 + margins_h * 0.7071067811865475244 );
92
+ double const cghx = cgy * 0.7071067811865475244 ;
93
+ double const cgsize = (cgx < cghx) ? cghx : cgx;
94
+ double const margins_ws = margins_w * cgsize;
95
+ double const margins_hs = margins_h * cgsize;
96
+ double const agx = pgx - margins_ws;
97
+ double const agy = pgy - margins_hs;
98
+
99
+ double const x_scale = (agx > 0.0 ) ? (agx / pagew) : 1.0 ;
100
+ double const y_scale = (agy > 0.0 ) ? (agy / pageh) : 1.0 ;
101
+
102
+ m_scaleFactor_X = x_scale;
103
+ m_scaleFactor_Y = y_scale;
75
104
}
76
- m_scaleFactor_Y = m_scaleFactor_X;
77
- }
78
- else
79
- {
80
- m_scaleFactor_X = x_scale;
81
- m_scaleFactor_Y = y_scale;
105
+ // The rectangle needs to be both shifted and scaled,
106
+ // as that's what AbstractImageTransform::scale() does,
107
+ // which we call in absorbScalingIntoTransform().
108
+ QPointF const p_tl = m_innerRect.topLeft ();
109
+ QPointF const p_br = m_innerRect.bottomRight ();
110
+ double const p_tl_xs = p_tl.x () * m_scaleFactor_X;
111
+ double const p_tl_ys = p_tl.y () * m_scaleFactor_Y;
112
+ double const p_br_xs = p_br.x () * m_scaleFactor_X;
113
+ double const p_br_ys = p_br.y () * m_scaleFactor_Y;
114
+
115
+ QPointF const p_tl_s (p_tl_xs, p_tl_ys);
116
+ QPointF const p_br_s (p_br_xs, p_br_ys);
117
+ m_innerRect = QRectF (p_tl_s, p_br_s);
82
118
}
83
119
84
- // The rectangle needs to be both shifted and scaled,
85
- // as that's what AbstractImageTransform::scale() does,
86
- // which we call in absorbScalingIntoTransform().
87
- QPointF const p_tl = m_innerRect.topLeft ();
88
- QPointF const p_br = m_innerRect.bottomRight ();
89
- QPointF const p_tl_s (p_tl.x () * m_scaleFactor_X, p_tl.y () * m_scaleFactor_Y);
90
- QPointF const p_br_s (p_br.x () * m_scaleFactor_X, p_br.y () * m_scaleFactor_Y);
91
- m_innerRect = QRectF (p_tl_s, p_br_s);
92
- }
93
-
94
- if (have_content_box)
95
- {
96
120
m_middleRect = margins.extendContentRect (m_innerRect);
97
121
}
98
122
else
0 commit comments