Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Keeping receipt prices aligned when item names wrap

Put Coffee below Almond croissant with apricot jam on a narrow receipt. The croissant name wraps onto a second line. If the price column advances once per item, the coffee price ends up next to apricot jam . Repceipt's generator draws names and prices in separate text blocks. The two-column format is a familiar pattern on paper receipts, as shown in Repceipt's receipt design notes . Reserve space…

When item names on a receipt wrap onto multiple lines, keeping the corresponding prices aligned becomes a challenge. Repceipt's receipt generator handles this by treating names and prices as separate text blocks. The generator works with a preset width, which determines the number of columns available for each item's label and price.

For instance, a 58 mm preset offers 30 columns, while an 80 mm preset provides 42 columns. To calculate the space for each character, the generator divides the available width by the number of columns, then sizes the monospaced font accordingly.

The generator formats the price and label together before they wrap onto different lines. For example, "$6.50" consumes five columns, leaving 24 columns for the label at a 30-column width. After formatting the price as "6,50 EUR," which takes up eight columns, 21 columns remain for the label. The layout function pairs each label-label pair and processes them line by line, distributing the text across lines based on the available space.

This process creates a two-column receipt, with the price column shifting down when the label wraps onto multiple lines.

Both the preview and export use the same layout, ensuring that labels and prices align properly. The generator outputs two text blocks, one for labels and one for prices, both aligned left and right, respectively. When changing the paper setting, the layout recalculates, and the sections below the items adjust to fit the new height.

A regression test using a lengthy item name confirms that both blocks start at the same y-coordinate and that the price column correctly includes blank entries for continued lines. A simple visual test involves adding a short item after a long one; a missing blank line becomes apparent upon comparison.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

How to fix 'Too many open files' (EMFILE) before it takes your site down: ulimit, systemd and the leak behind it

Uptime monitoring from outside your own infrastructure that alerts you the minute your site goes down — upordown.online It usually shows up in a log as one of these: accept4() failed (24: Too many…

  • EMFILE error caused by insufficient file descriptor limit per process
  • Diagnose by checking ulimit -n and open files in /proc/$pid/limits
  • Raise limit via systemd unit file or Nginx configuration

Should planned maintenance count against your uptime number? Let's argue about it

Uptime monitoring from outside your own infrastructure that alerts you the minute your site goes down — upordown.online Read the small print of almost any hosting or SaaS SLA and you'll find a…

  • Some hosting and SaaS SLAs exclude planned maintenance from uptime numbers.
  • Excluding maintenance measures reliability, not failures.
  • Reporting two numbers: internal for zero-downtime decisions, external for SLA.

Shopify Magic for Product Descriptions: A Drafting Aid, Not a Fact Checker

Originally published on Tool & Till . Shopify Magic can generate a product-description draft from details such as a product title and keywords.

  • Shopify Magic generates product descriptions from basic details.
  • Requires human oversight and fact-checking before publishing.
  • Merchants must verify AI tool's availability in their account.

Why a 100% benchmark score is a red flag, not a win

A model hit 100% on a benchmark this week and it was reported as a milestone. It is not one. It is a benchmark that has stopped being able to tell you anything, and the moment it saturates is the…

  • A 100% benchmark score raises red flags, not celebrating a victory.
  • Saturated benchmark has no room for further differentiation between models.
  • Reporting distance to the ceiling provides more informative than raw benchmark score.

More from Monday 23 November →