Git Product home page Git Product logo

Comments (4)

dirkesquire avatar dirkesquire commented on July 17, 2024

I have the same problem. I wonder if python-pptx is really even able to calculate the correct size. The calculation seems to only happen when you open the Excel file, and slightly tweak the shape size, or the text.
This is a big problem for exports, because nothing really ever fits onto the single slide properly.

from python-pptx.

MartinPacker avatar MartinPacker commented on July 17, 2024

Calculating the correct size would require using font metrics - which I don't believe python-pptx has access to or understanding of.

from python-pptx.

dirkesquire avatar dirkesquire commented on July 17, 2024

I just found this method which looks interesting:

shape.text_frame.fit_text()

It doesn't quite work for me because I'm running linux in a docker container which is an unsupported OS, but it might work for others.

It seems that python-pptx does have some understanding of fonts (although I'm unsure if font 'metrics' is a specific term).
The following class looks interesting:
pptx.text.fonts.py - especially the _best_fit_font_size method.

from python-pptx.

MartinPacker avatar MartinPacker commented on July 17, 2024

If you want to know how long a certain character string is you need font metrics - which describe the width of pairs of neighbouring characters. The only exception to this is fixed-pitch fonts.

from python-pptx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.