When printing labels, price tags, and other formats with limited sizes, there is a challenge where design approaches for such reports are constrained. In such conditions, the text object can only grow to certain sizes, and splitting or migrating the text to another page is not possible. How can we fit product composition and other data on a single label without cutting the information? The answer is simple—to reduce the content!
Starting from version 2023.3, we have added to the reporting engine FastReport VCL another powerful tool— reducing the text in the “Text” object by scaling the content.
Let’s look at a simple example of a price tag with product ingredients. Such a price tag is printed on prepared paper using a label printer, so there are physical restrictions on the amount of printed text. But the composition can vary from 3 to several dozen words.
To create such a report, we will use the function of creating multi-column reports. You can find how to create such a report in the user manual. Let’s use the example of creating a simple report with two columns, as in the figure below. We will not delve into creating a report but will concentrate on the necessary functionality. A ready-made example of a report can be downloaded here.
Let’s run the report for the building.
As a result, the preview shows that the table contains products whose composition consists of dozens of words, and it does not fit on the price tag with the current font size. The way out of this situation is obviously to reduce the font size.
Let’s return to the report designer, select the object and the text that does not fit into the borders, and then open the object inspector.
The functionality we need is controlled by the ContentScaleOptions property set. Let’s take a closer look at it.
AutoScale—disabled by default, the property sets the auto text scaling mode.
casStatic mode enables text to be scaled until it fits within the container or the extreme bounds of the constraints are reached (Constraints.MaxStepValue and Constraints.MinStepValue properties).
casStatic mode is great for use in a report with price tags, let’s turn it on and run the report for building.
Based on the generated report, you can see that the text is scaled not only to reduce its size but also to increase it. This allows you to fill a large container. This may be useful for some reports, but in this case it is unnecessary. Let’s return to the report designer and disable the cstGrow flag for the ContentScaleOptions.ScaleType property. Let’s run the report for the building.
Now FastReport VCL prints price tags reducing the font size if the text does not fit into the object. We have achieved the desired result by switching just two properties.
The example with labels is one of the most common, but sometimes a band with growing objects needs to be placed on the page without a break. If there are several objects with text on such a band, we can sacrifice the font size in some of them and compress the entire container. Let’s look at how this works using a simple example with random data (you can download the template here).
In this example, each text object outputs large paragraphs of text, thereby stretching and shifting the underlying objects. After running the report with demo data, the report will look like the screenshot.
As you can see, if there is a large amount of text, the band will be divided into two pages (in our case, with a break in the objects). What to do if we need to place the data on one page? The AutoScale mode set to casStatic is not suitable for this case, because objects have a dynamic height, calculated during the report generation. In addition, stretched objects displace the underlying ones. For this case, FastReport VCL has another object scaling mode, enabled by setting the AutoScale to the casDynamic property.
Let’s set the AutoScale property of the MainText object to the casDynamic and look at the report rendering result.
MainText object is reduced in size, and the entire band fits on one page. But what if you need to proportionally compress text across multiple objects?
Let’s set the AutoScale property of the BottomText object to the casDynamic and look at the report-building result.
As a result, both objects reduced the font size until the band fit completely on the page.
FastReport VCL allows you to control object compression. Each cycle of passing through objects reduces the font in objects by a given step, which is set for the object in the ContentScaleOptions.StepValue property. This will continue until the band fits on the page or the extreme constraints are reached (the Constraints.MaxStepValue and Constraints.MinStepValue properties).
In addition, each object can be processed only at a given iteration of passing through the objects. If you want the first two reduction iterations to process only the BottomText object, just set the ContentScaleOptions property. For the Constraints.MinIterationValue method, assign a value of 3 to the MainText object (it will skip the first two iterations). After the report is rendered, it will have the following appearance.
As you can see, in the first two iterations, our report engine only compressed the BottomText object, and as a result, its contents are at a smaller scale. Visually, iterations can be represented as follows.
This iterative approach to scaling content (or text) allows the reporting engine to prioritize which objects to compress and in what order to achieve optimal results.
This approach can negatively affect the speed of report generation with a large number of objects. Therefore, the number of iterations can be limited at the report engine level by setting the TfrxReport.EngineOptions.ContentScaleMaxIterations property (default 10).