jorisschellekens / borb

borb is a library for reading, creating and manipulating PDF files in python.
https://borbpdf.com/
Other
3.37k stars 148 forks source link

BUG: Digits in OrderedList not scaled with `font_size` #163

Closed swasher closed 1 year ago

swasher commented 1 year ago

Describe the bug Digits in Ordered list not scaled with font_size, i.e. rendering with default 12 font size.

Code Sample

if printsheets:
    table = FixedColumnWidthTable(number_of_columns=7, number_of_rows=len(printsheets)+1)

    # header
    table.add(TableCell(Paragraph("Name", font_color=X11Color("White")), background_color=X11Color("SlateGray")))
    table.add(TableCell(Paragraph("Descr", font_color=X11Color("White")), background_color=X11Color("SlateGray")))
    table.add(TableCell(Paragraph("Press", font_color=X11Color("White")), background_color=X11Color("SlateGray")))
    table.add(TableCell(Paragraph("Tiraz", font_color=X11Color("White")), background_color=X11Color("SlateGray")))
    table.add(TableCell(Paragraph("F", font_color=X11Color("White")), background_color=X11Color("SlateGray")))
    table.add(TableCell(Paragraph("B", font_color=X11Color("White")), background_color=X11Color("SlateGray")))
    table.add(TableCell(Paragraph("Detals", font_color=X11Color("White")), background_color=X11Color("SlateGray")))

    for sheet in printsheets:
        table.add(Paragraph(sheet.name, font_size=9))
        table.add(Paragraph(sheet.description, font_size=9))
        table.add(Paragraph(sheet.printingpress.name, font_size=9))
        table.add(Paragraph(str(sheet.tiraz), font_size=9))
        table.add(Paragraph(sheet.color_front_text, font_size=9))
        table.add(Paragraph(sheet.color_back_text, font_size=9))

        # add detals
        if sheet.detal_set.all():
            details: OrderedList = OrderedList()
            for x in sheet.detal_set.all():
                details.add(Paragraph(x.name, font=ptserif_font, font_size=6))    <==== there I setting up OrderedList font size
            table.add(details)
        else:
            table.add(Paragraph(''))

    table.set_padding_on_all_cells(Decimal(2), Decimal(2), Decimal(2), Decimal(2))
    layout.add(table)

Expected behaviour Digits in OrderedList must have same font properties (font, size, color etc) as a inline text.

Screenshots image

Desktop

jorisschellekens commented 1 year ago

I checked the behavior in Microsoft Word. The font_size and font_color seem to match the list-item. I've applied a fix for OrderedList. I am still going to have to revise UnorderedList (to make the bullet characters match) and RomanNumeralList

image

jorisschellekens commented 1 year ago

RomanNumeralOrderedList has also been modified:

output_004_ground_truth

swasher commented 1 year ago

Can't reproduce it. Reduce program to minimal code, result:

image

#!chapter_003/src/snippet_001.py
from borb.pdf import OrderedList
from borb.pdf import SingleColumnLayout
from borb.pdf import PageLayout
from borb.pdf import Paragraph
from borb.pdf import Document
from borb.pdf import Page
from borb.pdf import PDF
from borb.pdf import X11Color
from decimal import Decimal

colors = ['Blue','Red','Cyan','Orange','Violet','Pink']

def main():

    # create Document
    doc: Document = Document()

    # create Page
    page: Page = Page()

    # add Page to Document
    doc.add_page(page)

    # set a PageLayout
    layout: PageLayout = SingleColumnLayout(page)

    # add OrderedList of 3 Paragraph objects

    fruits = OrderedList()

    fs = Decimal(4)

    for item in colors:
        fruits.add(Paragraph(item, font_size=fs, font_color=X11Color(item)))
        fs += 3

    layout.add(fruits)

    # store
    with open("output.pdf", "wb") as out_file_handle:
        PDF.dumps(out_file_handle, doc)

if __name__ == "__main__":
    main()
jorisschellekens commented 1 year ago

I haven't done a release yet. So it's quite natural you can't reproduce it yet. You'll need to wait for me to actually make a release.

jorisschellekens commented 1 year ago

I am now running the tests. If they succeed I will build a temporary release (which I will attach to this issue) so you can continue using borb. I will also attach the test results so you can be assured this bugfix did not damage any other functionality.

jorisschellekens commented 1 year ago

borb test report.pdf borb-2.1.12-dist.zip