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

CentimetersToPixels not working for marginLeft and marginTop positioning #248

Closed
basjan opened this issue May 26, 2014 · 2 comments
Closed
Assignees
Milestone

Comments

@basjan
Copy link
Contributor

basjan commented May 26, 2014

My daytime job took so much time last two weeks, that I was not able to contribute. However, it has become quieter and I resynced my development tree.
All of a sudden some test code did not work any longer. For positioning an image and two textboxes, I used the following style:

$textbox = $section->addTextBox($style = array(
    'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4.5),
    'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(17.3),
    'positioning' => 'absolute',
    'posHorizontalRel' => 'page',
    'posVerticalRel' => 'page',
    'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.3),
    'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(9.9),
    'stroke' => 0,
    'innerMargin' => 0,
    'borderSize' => 1,
    'borderColor' => '',
    'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE
));

Using this code, no longer positions the image or textbox correctly. The position was simply marginLeft=0 and marginTop=0. When I change the relevant part into:

    'marginLeft' => 578, 
    'marginTop' => 374,   

The image and textbox are correctly positioned. Note, that 'width' and 'height' do not need to be changed.
I cannot find why this behaviour is all of a sudden present. It might be a result of static vs dynamic functions, but my knowledge in this respect is very limited.

@ivanlanin ivanlanin added the Bug label May 26, 2014
@ivanlanin ivanlanin added this to the 0.11.0 milestone May 26, 2014
@ivanlanin ivanlanin self-assigned this May 26, 2014
@ivanlanin
Copy link
Contributor

I guess I created the bug when implying more strict value checking for styles. marginLeft and marginTop only accepted integer value. I changed the code so that both props can accept float value. These are the changes that I made to fix the bug: d9a2c4c

Bugfix pushed. Please retest. Thanks.

@basjan
Copy link
Contributor Author

basjan commented May 26, 2014

Thank you Ivan, that solved the issue !

@basjan basjan closed this as completed May 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants