How to create a price label with product ingredients in the report control FastReport VCL

When printing labels, price tags, and other formats with limited sizes, the design methods for such reports are limited, which is a challenge. In this case, the text object can only grow up to a certain size, and it is not possible to split or move the text to another page. How can we put product ingredients and other data on a single label without removing the information? The answer is simple – reduce content!

    FastReport.VCL download icon-default.png?t=N7T8https://www.evget.com/product/233

Starting with version 2023.3, we have added another powerful tool to the reporting engine FastReport VCL - reduce text in "Text" objects by scaling the content.

Let’s look at a simple example of a price tag with product ingredients. Such price labels are printed on prepared paper using a label printer, so there is a physical limit to the amount of printed text. But the composition can range from 3 words to dozens of words.

To create such a report, we will use the functionality to create multi-column reports. You can find out how to create such reports in the user manual. Let's take the example of creating a simple report with two columns as shown in the image below. We won't delve into how to create reports, but will focus on the necessary functionality.

Report templates in designer

Let's run a report for this building.

Build report

As a result, the preview shows that the table contains products consisting of dozens of words, and it does not fit the price tag in the current font size. The obvious solution to this situation is to reduce the font size.

Let's return to the report designer, select the object and the text that doesn't fit within the border, and open the Object inspector.

Properties in the Object Inspector

The functionality we need is controlled by the ContentScaleOptions property set.

Autoscale —Disabled by default, this property sets the automatic text scaling mode.

casStatic mode allows text to be scaled until it fits the container or reaches the limits of the constraints ( Constraints.MaxStepValue and Constraints.MinStepValue properties ).

casStatic mode is great for use in reports with price tags, let's open it and run the report to build.

Build report

Based on the generated report, you can see that the text is not only scaled, but also increased in size. This allows you to fill a large container. This may be useful for some reports, but is not necessary in this case. Let's go back to the report designer and disable the cstGrow flag of the ContentScaleOptions.ScaleType property. Let's run a report for this building. ,

Build report

FastReport VCL now prints price labels and reduces the font size if the text does not fit into the object. We achieved the desired result just by switching two properties.

The labeled example is one of the most common examples, but sometimes it is necessary to place a band with growing objects on the page without interruption. If there are multiple objects with text on such a band, we can sacrifice the font size of some of them and compress the entire container. Let's see how it works using a simple example with random data ( you can download the template here ).

Report templates in designer

In this example, each text object outputs a large block of text, stretching and moving the underlying object. After you run the report with the demo data, the report will look like the screenshot.

Build report

As you can see, if there is a lot of text, the area will be divided into two pages (in our case there is a break in the object). What if we need to fit the data on one page? Autoscaling mode set to casStatic is not suitable for this case because the object has a dynamic height that is calculated during report generation. Additionally, stretched objects displace underlying objects. For this case, FastReport VCL has another object scaling mode, which is enabled by setting AutoScale to the casDynamic property.

We set the AutoScale property of the MainText object to casDynamic and see the report rendering results.

Build report

The size of the MainText object is reduced and the entire area fits on one page. But what if you need to compress text proportionally across multiple objects?

Let’s set the BottomText object’s AutoScale property to casDynamic and see the report build results.

Build report

As a result, both objects reduce the font size until the band completely fits the page.

FastReport VCL allows you to control object compression. Each cycle passed through the object decreases the font in the object by the given step, which is set for the object in the ContentScaleOptions.StepValue property. This continues until the region fits the page or reaches the limit constraints ( Constraints.MaxStepValue and Constraints.MinStepValue properties).

Additionally, each object can only be processed within a given iteration of the passed object. If you want the first two reduction iterations to process only BottomText objects, just set the ContentScaleOptions property. For the Constraints.MinIterationValue method, assign the value 3 to the MainText object (it will skip the first two iterations). Once the report is rendered, it will have the following appearance.

Build report

As you can see, in the first two iterations, our reporting engine only compressed the BottomText object, so its content was proportionally smaller. Visually, iteration can be represented as follows.

Build report

This iterative method of scaling content (or text) allows the reporting engine to prioritize which objects to compress and in what order to achieve the best results.

This approach can negatively impact the speed of report generation for large numbers of objects. Therefore, the number of iterations can be limited at the report engine level by setting the TfrxReport.EngineOptions.ContentScaleMaxIterations property (default is 10).

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/133345407