Error: Tiled PDF : field values not taken into account if one of them is smaller than 0,3

Issue #570 resolved
Ronan Le Tiec created an issue

In the Version 0.5.0.1562a on an ubuntu 16.04

The default left margin in the tiled pdf is to small for my printer, so I wanted to set the left field value to 1 in the "create a layout"-dialog. I left the other values at 0.

It didn't have any effect. After several trials, I found that if any of the field values is < 0,3 then none of the field values defined in the dialog are taken into account in the tiled pdf. If all of the field values are >= 0,3 then they are taken into account.

In order to be able to set the left margin to 1 and leave the other to their default values, I need to set the following values left : 1 - right: 0,3 - top: 0,3 - bottom : 0,3

I would expect here to just have to edit the left value and leave the others as they are.

I don't know if this has anything to do with this, but everytime i click on "ok" to create the layout, I get the dialog "wrong fields - Fields go beyond printing, apply settings anyway?" it only doesn't appear when I check "ignore fields".

In the attachment I put the pattern that I've been editing with the corresponding measurements, in case needed for testing.

Comments (38)

  1. Ronan Le Tiec reporter

    In the version 0.5.0.1568a on ubuntu 16.04,

    unfortunatly the fiel values are still not taken into account properly to set the margins in the tiled PDF. Now there is the following behaviour:

    if one of the field value is smaller than 0,3 then in the tiled PDF the added margins are all equal to 0.

    if all of the field values are equal or greater than 0,3 then in the tiled PDF the added margins are exactly equal 0,3 regarless of the values defined.

  2. Roman Telezhynskyi repo owner

    @ronanletiec, i can't repeat your result. This issue will stay open, but i need more information.

    • Say me your Qt version.
    • When you set margins and click OK do you see warning about printer fields?
    • What do you answer?
    • Do you see new warning "Cannot set printer margins"?
  3. Ronan Le Tiec reporter

    I use Qt 5.6

    It looks like the limit value is not 0,3 but 0,2960.

    if at least one of the margins in < 0,2960 then i get the Warning about the print fields

    • if i click yes, then there are no margins at all in the tiled pdf, the fields values i entred in the dialog are still the same afterwards
    • if i click no, then the margins that i set < 0,2960 (i used 0,1) are overwritten and set automatically to 0,2960. The margins in the pdf seems to be then 0,2960

    if all margin are >= 0,2960, then

    • i don't get the warning about printer fields.
    • I get the warning "cannot set printer margins" when i click on File > Layout > create tiled pdf or preview tiled pdf
    • no matter the values, in the pdfs the margin seems to all be equal to 0,2960

    I hope this helps you. I can provide you more informations if you need.

  4. Roman Telezhynskyi repo owner

    I use Qt 5.6

    Perfect.

    It looks like the limit value is not 0,3 but 0,2960.

    Yes, this is standard min margin value.

    if i click yes, then there are no margins at all in the tiled pdf, the fields values i entred in the dialog are still the same afterwards

    This is very odd.

    if i click no, then the margins that i set < 0,2960 (i used 0,1) are overwritten and set automatically to 0,2960. The margins in the pdf seems to be then 0,2960

    This is correct behavior.

    I get the warning "cannot set printer margins" when i click on File > Layout > create tiled pdf or preview tiled pdf

    Because you can't set margins you want you can't get result you want. And i still don't understand why.

    I hope this helps you. I can provide you more informations if you need.

    Thanks. I need time to think. Keep in touch.

  5. Roman Telezhynskyi repo owner

    @ronanletiec, can you try print origin image?

    I have an idea. And i need your help to check it. Create a pattern that will match for A4 and check what margins you will get there.

  6. Ronan Le Tiec reporter

    I'm not sure if I understood exactly what you need, but here is what i did:

    I created a simple square of 10x10 (+ 1cm seam allowance), selected the template A4, so that I had a pattern that fits on a A4 Document.

    With all field to 0, the orientation in portrait, and the autocrop NOT selected, I get a pdf with 2 pages : grid(1,1) and grid(2,1). The Grid(1,1) looks exactly the same as the layout, the square is positioned in the upper right corner.

    If I set right = 2, the rest to 0, then in the tiled pdf, the square is positioned 2 cm away from the right border of the document. Besides at the bottom of the first page and top of the second page, they are no dotted lines (which is right).

    If I set top = 2, the rest to 0, then I get only one page grid(1,1), but the square isn't positioned to 2cm to the top like it was for the right.

    If I set all fields to 0,2960 or other bigger values, I get 4 pages, I see the cutting lines and no matter the values, they all have the margin 0,2960.

    Is this what you needed me to do?

    The more I use the field values, the more I get confused about how they work. They are used as margin for the entired document, and also as margin for the cutting lines in the pdf, is that right?

  7. Ronan Le Tiec reporter

    Oh, with "print origin image", did you mean "File > Layout > print or print preview"?

    If so, then when the field values are bigger than 0.2960, in the preview the square even seems to go beyond the page limits. I made a sreenshot for it:

    square_test.jpg

  8. Roman Telezhynskyi repo owner

    I asked you create a pattern that will match for A4 and print usual way (without tiled print). But issue #574 shows that most probably my theory is wrong.

  9. Ronan Le Tiec reporter

    I looked into the code, I think that part of the problem is that in the file

    dialoglayoutsettings.cpp, function "DialogAccepted", the else part of the if-statement of line 588 is missing.

    When the margins are all greater than the min value, then the generator->SetPrinterFields(true, GetFields()); is never called.

  10. Ronan Le Tiec reporter

    Case for when some of the margins are smaller than min value:

    I found out, that in the function void MainWindowsNoGUI::PrintPages(QPrinter *printer), when the printer has fullPage = true, then the printer->pageRect(...) doesn't take the margins into account at all, it returns the same value as the paper size.

    If I force fullPage to false at the beginning of the function, then it works. I'm not sure if it has consequences though. What do you think?

  11. Roman Telezhynskyi repo owner

    I found out, that in the function void MainWindowsNoGUI::PrintPages(QPrinter *printer), when the printer has fullPage = true, then the printer->pageRect(...) doesn't take the margins into account at all, it returns the same value as the paper size.
    If I force fullPage to false at the beginning of the function, then it works. I'm not sure if it has consequences though. What do you think?

    It is correct behavior. See void QPrinter::setFullPage(bool fp).

  12. Ronan Le Tiec reporter

    Yes true, and it's logical.

    The documentation says "so the application must account for the margins itself."

    It means that in the PrintPages function, if fullPage = true, then we need to calculate the margins of the printer ourselves. Right now it is not done.

    Should I try to see if I get the margins taken into account?

  13. Roman Telezhynskyi repo owner

    You are right about this place, but this is not critical in this case. The code calcs scaling factor, so this not our place to worry about margins.

  14. Ronan Le Tiec reporter

    Ok.

    Mm then I don't really know where to set them correctly. If you have an idea, I can take a look.

  15. Roman Telezhynskyi repo owner

    Yes, you are right we should care about margins manually.

    First place to look is VPoster::PageRect(). It definitely returns wrong page rect in case of fullPage==true even if setted margins.

  16. Roman Telezhynskyi repo owner

    The second place is:

    QRectF source;
    isTiled ? source = poster->at(index).rect : source = paper->rect();
    QRectF target(0, 0, source.width() * scale, source.height() * scale);
    
    scenes.at(paperIndex)->render(&painter, target, source, Qt::IgnoreAspectRatio);
    

    The rect target is wrong if fullPage == true. The top left corner is wrong. I mean this 0, 0.

  17. Ronan Le Tiec reporter

    I'm looking at the code now and will tell you when I find something out. Thanks for the hint.

  18. Ronan Le Tiec reporter

    For the first place, i did this :

    //---------------------------------------------------------------------------------------------------------------------
    QRect VPoster::PageRect() const
    {
        // Because the Point unit is defined to be 1/72th of an inch
        // we can't use method pageRect(QPrinter::Point). Our dpi value can be different.
        // We convert value yourself to pixels.
        const QRectF rect = printer->pageRect(QPrinter::Millimeter);
    
        if(printer->fullPage())
        {
            QMarginsF pMargins = printer->pageLayout().margins();
            QRectF newRect = rect.marginsRemoved(pMargins);
            const QRect pageRectFP(0, 0, qFloor(ToPixel(newRect.width())), qFloor(ToPixel(newRect.height())));
            return pageRectFP;
        }
        else
        {
            const QRect pageRect(0, 0, qFloor(ToPixel(rect.width())), qFloor(ToPixel(rect.height())));
            return pageRect;
        }
    }
    

    and for the second i did this :

        QRectF source;
        isTiled ? source = poster->at(index).rect : source = paper->rect();
    
        qreal x,y;
        if(printer->fullPage())
        {
            QMarginsF printerMargins = printer->pageLayout().margins();
            x = qFloor(printerMargins.left() / 25.4 * PrintDPI); // Mm to pixels with current dpi.;
            y = qFloor(printerMargins.top() / 25.4 * PrintDPI); // Mm to pixels with current dpi.;
        }
        else
        {
            x = 0; y = 0;
        }
    
        QRectF target(x, y, source.width() * scale, source.height() * scale);
    

    And it works well :-) for the calculation of "... / 25.4 *PrintDPI ", I wanted to use the function VPoster::ToPixel, but it's private. So to test I just used quickly the calculation-formula.

    What do you think?

  19. Roman Telezhynskyi repo owner

    What do you think?

    Great. Good job.

    for the calculation of "... / 25.4 *PrintDPI ", I wanted to use the function VPoster::ToPixel, but it's private. So to test I just used quickly the calculation-formula.

    Use method ToPixel() from file def.h in library vmisc.

    Only one task left. Make it work with Qt less than 5.3. We support Qt 5.0. Code should build on it too.

  20. Ronan Le Tiec reporter

    Yes true, x & y should be scaled as well then.

    I used the ToPixel Function, it works all fine like this.

    I didn't think of older versions of Qt, good point. I will test it tomorrow then, and if everything is fine, I will do a pull request.

    Now it's time for a break, enough computer for today :-)

  21. Roman Telezhynskyi repo owner

    Merged in ronanletiec/valentina/feature (pull request #145)

    Resolved issue #570. Error: Tiled PDF : field values not taken into account if one of them is smaller than 0,3.

    → <<cset c7708664c334>>

  22. Roman Telezhynskyi repo owner

    Merged in ronanletiec/valentina/feature (pull request #145)

    Resolved issue #570. Error: Tiled PDF : field values not taken into account if one of them is smaller than 0,3.

    → <<cset c7708664c334>>

  23. Log in to comment