Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tibetan pagination #1786

Closed
RimeOCRLIB opened this issue Dec 25, 2022 · 5 comments
Closed

Tibetan pagination #1786

RimeOCRLIB opened this issue Dec 25, 2022 · 5 comments
Labels
CSS Questions about how to do something with CSS

Comments

@RimeOCRLIB
Copy link

For Tibetan text print layout it is need insert ༄༅། in beginning of first text string on every odd page.

Please help us understand how apply this rule for page layout

With best regards
Open Source Buddhism Library
Alexander Stroganov
tibetan pagination

@liZe liZe added the CSS Questions about how to do something with CSS label Dec 27, 2022
@liZe
Copy link
Member

liZe commented Dec 27, 2022

Hi!

As far as I know, the @page rules don’t provide a way to add something in the text of the page content. So, if you don’t know before the layout on which page each block is displayed, I don’t think that there’s a way to add this character 😢️.

Maybe there’s something included somewhere in a CSS specification to handle this use case. There’s a dedicated section in a W3C document, but not CSS feature seems to be linked to this requirement.

The next step to solve this problem is to find a feature in the CSS specification that could be useful. And if it doesn’t exist, it should be interesting to open an issue on the CSSWG’s repository explaining this requirement and asking for a feature that could help.

@RimeOCRLIB
Copy link
Author

RimeOCRLIB commented Dec 27, 2022

Look like for that rule implementation it is need access to Python pages and phrases rendering rules.
For that reason we can not use plain QT WebView engine for that. Does Weasyprint have Python access to phrases and pages level of HTML render?

@liZe
Copy link
Member

liZe commented Dec 27, 2022

Does Weasyprint have Python access to phrases and pages level of HTML render?

It’s theoretically possible to change the content on the fly, but you’ll need to rely on a private API that may change in the future.

I’ve used the sample you provided in the other issue and I’ve added some code before this line:

if 30 < position_y < 31:
    child = box
    child_skip_stack = skip_stack
    while isinstance(child, boxes.ParentBox):
        if child_skip_stack:
            skip = tuple(child_skip_stack.keys())[0]
            child_skip_stack = child_skip_stack[skip]
        else:
            skip = 0
        child = child.children[skip]
    if child_skip_stack:
        skip = tuple(child_skip_stack.keys())[0]
    else:
        skip = 0
    child.text = child.text[:skip] + 'abc' + child.text[skip:]

book.pdf

Of course, that’s a huge hack, and you’ll need more work to get something more robust that than.

The test of the position (the first line) is a quick and dirty way to check that we’re at the top of the page (and not on the second line, or in a page margin). There’s probably a much better way to do this…

The while loop takes the box (that’s the line box) and recursively finds the current child in it, using skip_stack (that’s a pointer to the current position in the tree). It goes through the tree, taking each time the nth child, until it finds a box that’s not a parent box. At the end, child is the text box that’s displayed at the top of the page, and child_skip_stack is the current position in this text.

We then insert the text we want at the current position. Here’s, it’s 'abc', but of course you can put the correct string instead.

You can modify WeasyPrint itself for your needs, or just monkey-patch the iter_line_boxes function, but either way it’s a hack that may be broken and may need to be fixed when you update WeasyPrint.

@RimeOCRLIB
Copy link
Author

RimeOCRLIB commented Dec 27, 2022

Great!
May be we may ask add Language tag in init CSS and set layout/inline.py handle this language tag?
It will need some time for us to read inline.py and try to set another rules.

One more question for now.
How we may detect page number in inline.py? This ༄༅ sign need set on odd pages and not on even pages.

Thank you from my heart for help.
Merry Christmas and Happy New Year.
Alexander

@liZe
Copy link
Member

liZe commented Dec 29, 2022

May be we may ask add Language tag in init CSS and set layout/inline.py handle this language tag?
It will need some time for us to read inline.py and try to set another rules.

The "clean" way would be to have a CSS specification we could follow. We never add unspecified behaviors directly in WeasyPrint, it’s already really hard and time consuming to implement the existing specifications 😄. But, of couse, you can hack WeasyPrint to fit your needs. It’s even possible to override WeasyPrint’s function without touching its code, that’s part of Python’s beauty (or ugliness, who knows?).

How we may detect page number in inline.py? This ༄༅ sign need set on odd pages and not on even pages.

The context variable has a current_page attribute.

Happy new year for you too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Questions about how to do something with CSS
Projects
None yet
Development

No branches or pull requests

2 participants