Reputation: 262
I have a project where I am dynamically creating a report. The number of columns may change, so I have figured out a table to help me determine which paper size to use. The size of fonts across and page sizes down. The intersecting numbers are numbers of columns. I would like to choose the combination with the largest font size and the smallest paper size. Is there an easy method to determining this combination? Any help is always appreciated.
EDIT
Here is a copy of the table.
I have been racking my brain trying to come up with a solution, but I don't even know where to start. When the report is created the exact number of columns may be different than what is listed in the table, but I want to select the next larger number listed in the table.
Upvotes: 0
Views: 45
Reputation: 262
I came up with the following solution, but I am wondering whether there is a more efficient method of doing the same thing.
I reversed the order of the fonts, shown above, and used the following code.
// Example number of columns
$NumColumns = 15;
//
$PageFont[0][0] = 7;
$PageFont[0][1] = 8;
$PageFont[0][2] = 8;
$PageFont[0][3] = 9;
$PageFont[1][0] = 10;
$PageFont[1][1] = 11;
$PageFont[1][2] = 12;
$PageFont[1][3] = 13;
$PageFont[2][0] = 13;
$PageFont[2][1] = 14;
$PageFont[2][2] = 15;
$PageFont[2][3] = 16;
$PageFont[3][0] = 16;
$PageFont[3][1] = 17;
$PageFont[3][2] = 19;
$PageFont[3][3] = 20;
$Font = NULL;
$Page = NULL;
// $x = Page Size
// $y = Font Size
for($x=0;$x<4;++$x) {
for($y=0;$y<4;++$y) {
if($PageFont[$x][$y] >= $NumColumns) {
$Page = $x;
$Font = $y;
break;
}
}
}
Upvotes: 0
Reputation: 1419
This is a multivariate problem with multiple solutions. It can be clearly seen that there is no unique solution for some numbers of columns (e.g. 13, 16).
As such, it depends which you value more - the larger font sizes or the smaller paper sizes.
I.e. it is unclear what your goal variable is.
You could create some sort of index or score to a combination based on:
So, as an example
You can then combine these scores in some way to produce a result.
How you combine those scores is then down to what you value most. Let p be paper saving and r be readability, you could have:
y = 5p + 2x
This would value paper saving over readability at a ratio of 2/5, or you could have:
y = e^p + e^x
So that they're both equally weighted, but exponentially, meaning a big font on big paper is better than a medium font on medium paper.
Once you have determined what the combination is with the lowest score that can satisfy your minimum needs, then you can choose the correct combination.
Upvotes: 1