Repository navigation
Label editor - fix image scaling, add barcode size, add part images, image and barcode wrapping options, better label preview - #1589
Open
calebwest-SS wants to merge 1 commit into
Conversation
…image and barcode wrapping options, better label preview
Contributor
Author
|
I did realize as I was writing up the PR just how much I had wrapped into one. I can split up into multiple PRs for cleaner checking and merging if that's preferable. |
Member
|
Yes splitting it up would be good. Thanks. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This reworks how images and barcodes are handled in the built in label editor, so that the editor pane matches the generated PDF and barcodes/images can be placed freely. Existing labels keep rendering as before (see Compatibility) unless they use features that were broken until now (e.g. image sizing).
My goal here was to make the label editor a much more WYSIWYG editor. Since placeholders are used, obviously there still may be differences, but overall it is much, much closer.
New editor screenshot:
Editor with manually placed barcode and image placeholder:

Generated pdf:

1. Image scaling and image styles in the PDF
Problem: Images resized in the editor were rendered with only their width changed in the PDF (CKEditor writes the width as style, but keeps the original
width/heightattributes and anaspect-ratiostyle, which dompdf does not support), so they were squashed. The CKEditor image styles (side, alignment) had no CSS on the label at all.alignCenterstyle instead of the class-less defaultblockstyle, so deliberately centered images can be told apart from unstyled images of existing labels (which keep their old position).PartDBLabelImageStyles), and the PDF renders both identically, so labels that are not edited again look the same.pxinstead of%(percentages were relative to the much wider editor, not to the label).2. Barcode size option
label_page_barcode.html.twig): 2D codes left of the text with a 4 mm gap, 1D codes at the bottom of the label with their caption. This also fixes 1D barcodes overlapping the text on small labels.Version20260929120000adds the nullable columnoptions_barcode_size(MySQL, SQLite, PostgreSQL). The field is included in profile import/export.3. Barcode placeholder ("Barcode" button)
<img class="partdb-barcode" style="float: right;">.4. Part image placeholder ("Part image" button)
object-fit, so this is calculated on the server and done with padding).read, andshow_privatefor private attachments), the same checks asAttachmentFileController.<img class="partdb-part-image" style="width: 80px; height: 60px;">.5. Editor improvements
line-height: 1.0, so the editor uses the measured dompdf line heights per font (1.2804 for the DejaVu fonts, separate values for Helvetica, Times, Courier and Unifont). The editor font size is now12pxlike the label (was12pt).LabelHTMLGenerator::getLabelEditorParameters()) and passed to the editor via a data attribute, instead of being duplicated in JS.6. dompdf workarounds
All of these are only applied to labels with wrapped images or placeholders (labels without them are not parsed or changed at all):
inline-blockinstead offloat(same geometry).// TODO handle when floating elements don't fitinBlock::process_float()) and ignoresclearon floats. For consecutive wrapped images, the server checks this like browsers do and moves images that do not fit into a new row via a top margin (with a clearing element as fallback if a height is unknown).Text::layout_line()), so it often ended up up to one line lower than in the editor. A spacer moves it directly below the images instead.<p> </p>. The space has a width in dompdf (but not in the editor), so such lines could be pushed below wrapped images. They are rendered as<p><br></p>instead.Compatibility with existing labels
Verified by comparing the dompdf layout (position and size of every element) of this branch against
master:[[BARCODE_*]]and[[IPN_BARCODE_*]]text placeholders, custom CSS for.qr/.C39/.C39-container, the grid classes in label content, unstyled images (inline and block), plain<figure>s, images in tables.master(JSON, XML, CSV) import without errors; the content is unchanged and the barcode size is empty.Intentional changes, which existing users may notice:
masterminds/html5; the output is equivalent (e.g.'becomes').The "Block image" and "Side image" buttons were removed from the image toolbar; they are replaced by Break text → centered and Wrap text → right.
Dependencies & requirements
No new dependencies. Uses
ext-gd(already required) for downscaling,masterminds/html5(already installed viasymfony/dom-crawler) for HTML processing, and Symfony'sMimeTypesfor the MIME type detection. The editor uses the CSS:has()selector (Chrome 105+, Firefox 121+, Safari 15.4+); in older browsers only some editor styling of placeholders is missing, the generated labels are not affected.Testing
LabelHTMLGeneratorTest(layouts, legacy layout preserved, placeholders, image fitting, float fitting, spacer, empty lines, editor parameters) andLabelPartImageProviderTest(image selection, part lots, fallback, permissions for private attachments, downscaling).master(SQLite, aftermigrate+ fixtures like in CI): no new failures compared tomaster(2552 vs. 2530 tests; the 16 OAuth test failures in my local setup occur identically onmaster).lint:yaml,lint:twig,doctrine:schema:validateandyarn buildpass.Known limitations