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

autosize text #71

Closed
desigennaro opened this issue Dec 11, 2014 · 20 comments
Closed

autosize text #71

desigennaro opened this issue Dec 11, 2014 · 20 comments

Comments

@desigennaro
Copy link

If the text is too large to fit in the box I would like it to automatically make the font size smaller. I assume that autoFit would be used, but I have been unable to get it working.

@Progi1984
Copy link
Member

@desigennaro Hi, I need more informations.

Have you got a sample source code for testing ?
Which writer do you use ?

Thanks :)

Link : http://www.officeopenxml.com/drwSp-text-bodyPr-fit.php (a:normAutoFit)
Link : http://openxmldeveloper.org/discussions/formats/f/15/p/5083/157934.aspx

@desigennaro
Copy link
Author

Our code is on a development network, but I have included a sample below. We are writing a PPTX file.

$shape = $slide->createRichTextShape()
  ->setHeight(150)
  ->setWidth(350)
  ->setAutoFit( 'spAutoFit' );
$textRun = $shape->createTextRun( $text );
$textRun->getFont()->setSize(14);

@desigennaro
Copy link
Author

Also, when using "normAutoFit" or "RichText::AUTOFIT_NORMAL" I get the following error upon opening the PPTX.

"PowerPoint found content in *filename.pptx" that it did not understand. This content has been removed and cannot be recovered."

@Progi1984
Copy link
Member

@desigennaro Have you tried to use this ?

->setHorizontalOverflow(RichText::OVERFLOW_CLIP)
->setVerticalOverflow(RichText::OVERFLOW_CLIP)
// or / and
->setWrap(RichText::WRAP_SQUARE)

@desigennaro
Copy link
Author

Yes, but I do not want the text to be cut off. My goal is to have the font size automatically decrease to allow all of the text to fit in the text box. I assumed (and I could be completely wrong) that is what one of the features of autofit is.

I also assumed that wrap was to set how the text wraps around a shape it may come in connection with.

@Progi1984
Copy link
Member

@desigennaro Have you a PPTX file which has that feature ? I want to analyze it.

PS : I haven't got Office :(

@desigennaro
Copy link
Author

@Progi1984 how would you like me to get the file to you? I am unable to upload it here. It is a PPTX file. I suppose you can unzip it and look at the xml....does that help?

@Progi1984
Copy link
Member

@desigennaro You can send me by mail (my nickname @ GMail Dot Com).

@desigennaro
Copy link
Author

@Progi1984 sent

First slide is with autosizing, second slide is without. Same text.

@Progi1984
Copy link
Member

@desigennaro Wow... I just try with parameters for normAutoFit but no works.

For this :
Replace in src\PhpPowerpoint\Writer\PowerPoint2007\Slide.php

$objWriter->writeElement('a:' . $shape->getAutoFit(), null);

by

$objWriter->startElement('a:' . $shape->getAutoFit());
if($shape->getAutoFit() == RichText::AUTOFIT_NORMAL){
  $objWriter->writeAttribute('fontScale', '47500');
  $objWriter->writeAttribute('lnSpcReduction', '20000');
}
$objWriter->endElement();

Link : http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.normalautofit(v=office.14).aspx

@Gyzmoo
Copy link

Gyzmoo commented Dec 18, 2014

Hi Progi,

I would like to create a Shape, (i don't know contents before), so i put a ridiculous height

$shape->setHeight(10)->setWidth(915)->setOffsetX(25)->setOffsetY(248)->setAutoFit( RichText::AUTOFIT_NORMAL );

After that i populate my shape with a long long text with createTextRun!

$textRun = $shape->createTextRun("Profitez de la bien nommée Costa del Sol en séjournant à Torremolinos à l'hôtel Amaragua. Son emplacement des plus agréables au bord d’une grande plage favorise un séjour en toute quiétude, à quelques pas seulement de l’animation.");

On the pptx generated, my shape have 10 height value can we create a shape with a textRun who have dynamic height ?

PS: I've tried your patch its seems it's didn't work, sry for my bad english

@Progi1984
Copy link
Member

@Gyzmoo Yes, I know that my patch doesn't work... It's a WIP so I try fixing that without PowerPoint.

For a shape with dynamic height, please create a new issue. Thanks.

@desigennaro
Copy link
Author

@Progi1984 Thanks for your first shot at it. I will work with what you have posted and keep this thread updated with any forward progress I can make.

To get the ball rolling.....in the RichText.php file on line 38 I noticed the following:

    const AUTOFIT_NORMAL = 'normAutoFit'; 

in the XML of an unzipped PPTX file an autofit element is:

<a:normAutofit fontScale="..." lnSpcReduction="..."/>

I assume this is going to be case sensitive ("F" vs "f")

@Progi1984
Copy link
Member

@desigennaro Good job :) It is the solution. OpenXML is case sensitive.
Just add accessors for fontScale and lnSpcReduction and I will push the patch today.

Progi1984 added a commit that referenced this issue Dec 19, 2014
@Progi1984
Copy link
Member

@desigennaro You can now use AutoFit with two options :

  • $fontScale permits to define the fontscale (in percentage)
  • $lineSpacingReduction permits to define the reduction of the line spacing (in percentage)
$oRichTextShape->setAutoFit(RichText::AUTOFIT_NORMAL, 47.5, 20);

Progi1984 added a commit that referenced this issue Dec 19, 2014
@Gyzmoo
Copy link

Gyzmoo commented Dec 22, 2014

When i use the setAutoFit( RichText::AUTOFIT_NORMAL, 50, 20); function,
i've to open my ppt generated, do any action in the file, move an object, add text on shape or any action, and this action will be resize automatically all my text on my file.pptx ?

I dont understand why the autoFit option are not OK on the file generated, i've to do an action manually for resize text policy...

@Progi1984
Copy link
Member

@Gyzmoo You must choose values for each percentage for each richtext shape that you use.

Why ? Because it's PowerPoint which makes the calculation to find the good value... And with code, it's the developer which has this job. May be an algorithm could permit to do this, but I have no clue for this solution.

@Progi1984 Progi1984 self-assigned this Dec 22, 2014
@Progi1984 Progi1984 added this to the 0.4.0 milestone Dec 22, 2014
@Gyzmoo
Copy link

Gyzmoo commented Dec 22, 2014

Hum i understand your solution but all my text on RichTextShape are generics. (i can have 1 words, 1 sentence or many sentences for each export!

@desigennaro
Copy link
Author

@Progi1984 Thanks for the help. It works great.

I am planning to use character count to determine how much I am going to shrink the text since I am using a slide template.

@Progi1984
Copy link
Member

@desigennaro No problem, it's a pleasure.... Just hard to work without Office 2k7/2k12...
If you find a good solution for that, we are opened to integrate it...

PS : I close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants