Tk Source Code

View Ticket
Login
Ticket UUID: 3403387
Title: Canvas Text Clipping
Type: Bug Version: None
Submitter: Created on: 2011-09-02 17:09:27
Subsystem: 05. Canvas Items Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Open Last Modified: 2011-09-03 00:09:29
Resolution: None Closed By:
    Closed on:
Description:
I have a specific rectangle that I want text to appear in, with any excess text being clipped ("overflow: hidden" in CSS/HTML terms); I'm told that I can either not limit width, and the text overflows left and right, or I can limit width, and the text overflows top and bottom.

A screenshot of the problem that I'm trying to solve is attached.

It would be really nice if I could limit the width *and* the height -- if the height limit was "number of lines of wrapped text" rather than pixels then that would be easy to use and probably easier to implement (I would imagine incrementing a counter with each line wrap, then breaking out of the loop when the number of lines reaches the limit)

If the bounding box could be specified in a way that scales when canvas.scale() gets called, that would be even better.

For the moment I'm manually storing a second copy of all the bits of text on screen, then manually calculating the width and truncating the text on every rescale -- but this seems like I'm duplicating a lot work that Tk has already done (it is already storing a copy of the full text, calculating the width, and then truncating in order to wrap the text -- all I want on top of that is for it to stop rendering after one line)
User Comments: added on 2011-09-03 00:09:29:

File Added - 422670: tk-canvas-uncropped-text.png

Attachments: