Bug 34555 - Make cropping handles for images (as in Draw/Impress) available for all LibreOffice applications
Summary: Make cropping handles for images (as in Draw/Impress) available for all Libre...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: UI (show other bugs)
Version: Inherited From OOo
Hardware: All All
: medium enhancement
Assignee: Not Assigned
QA Contact:
URL:
Whiteboard: EasyHack DifficultyInteresting Topi...
Keywords:
: 38920 48324 58682 61991 70482 88363 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-02-22 03:22 UTC by sasha.libreoffice
Modified: 2015-01-23 22:47 UTC (History)
26 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Image showing the crop tool on Impress and not on Writer (881.26 KB, image/jpeg)
2014-09-29 12:10 UTC, Pedro
Details
A patch that nearly worked but cannot be applied on current trunk (28.72 KB, patch)
2015-01-23 22:47 UTC, Philippe Jung
Details | Splinter Review

Description sasha.libreoffice 2011-02-22 03:22:11 UTC
In libreoffice I can crop images only by entering numbers it tab "Crop". No other way and no tools to crop.

Please, add tool to crop. For example like in Gimp.
Comment 1 Rainer Bielefeld Retired 2011-03-07 21:45:51 UTC
In DRAW clicking 'Crop' icon provides crop control marks, so I believe this one is more or less INVALID.

@sasha:
If that solution is not enough for your needs, please describe more exactly what you need. A simple reference to a pixel image editor is not sufficient.
Comment 2 sasha.libreoffice 2011-03-08 22:36:17 UTC
In Draw it works perfectly. Thanks for this improvement.
But in Writer I can not find this tool. And I work mainly in Writer.
Comment 3 Uwe 2011-05-13 05:37:53 UTC
(In reply to comment #1)
> In DRAW clicking 'Crop' icon provides crop control marks, so I believe this one
> is more or less INVALID.

The crop tool is working perfectly in Draw and Impress, but it is completely missing in Writer (correct me if I'm wrong). That is really annoying, because every time you want to insert an excerpt from an image into your document you first have to crop the original image using another program like Gimp.

There is in fact a crop tool in Writer if you open the image's properties. But that one is quite useless because you have to define the crop area by entering dimensions instead of simply using the mouse, which would be a much more intuitive approach. In addition, the existing tool is very inaccurate because you have to rely on a very small preview image.

Isn't there a possibility to simply transfer the crop tool from Draw and Impress to other parts of the suite?
Comment 4 Uwe 2011-05-18 02:33:56 UTC
By the way: Did you know, this feature has been requested for OOo since way back in 2002? You can find the other project's thread here:

http://openoffice.org/bugzilla/show_bug.cgi?id=3545

After almost 10 years, adding this quite basic functionality should really be targeted seriously...
Comment 5 giovanni.grazia 2011-05-25 03:49:34 UTC
+1 for adding a mouse operated image crop functionality in writer.
thanks
Comment 6 Roman 2011-07-03 06:55:58 UTC
+1. I need either. Would be perfect to see it in next release.
Comment 7 Rainer Bielefeld Retired 2011-07-03 07:11:30 UTC
*** Bug 38920 has been marked as a duplicate of this bug. ***
Comment 8 Dmitry 2011-09-25 11:41:38 UTC
+1. Please, do it in the next release. Often necessary function, but the present implementation is very-very inconvenient.
Comment 9 Roman 2011-12-02 07:29:13 UTC
Is it in plans of 3.5 release?
Comment 10 Björn Michaelsen 2011-12-23 11:49:25 UTC
[This is an automated message.]
This bug was filed before the changes to Bugzilla on 2011-10-16. Thus it
started right out as NEW without ever being explicitly confirmed. The bug is
changed to state NEEDINFO for this reason. To move this bug from NEEDINFO back
to NEW please check if the bug still persists with the 3.5.0 beta1 or beta2 prereleases.
Details on how to test the 3.5.0 beta1 can be found at:
http://wiki.documentfoundation.org/QA/BugHunting_Session_3.5.0.-1

more detail on this bulk operation: http://nabble.documentfoundation.org/RFC-Operation-Spamzilla-tp3607474p3607474.html
Comment 11 Roman 2011-12-26 00:35:04 UTC
yes, this bug still persists with the 3.5.0 beta1 or beta2
prereleases and this feature needs to be implemented.
Comment 12 wepmaschda 2012-02-04 09:10:45 UTC
It's a pity that this isn't implemented yet. I'm currently helping a small company on their decision what office-suite they will use from March on.

Currently the only reason why they are not able to use libreOffice is that there's no crop tool in writer. Their main procedure includes inserting a lot of images into documents and croping them a bit. Using a full image manip. program or the sliders in the dialog box would mean large decrease of efficiency.


From outside, copying the implementation from LO-Draw to LO-Writer doesn't seem to be much work. I haven't looked into the code yet. Is there someone who can really estimate, how much effort it will be to port this from LO-Draw to LO-Writer? Is it worth to create a build environment etc.?


Thanks for all the good work!
Comment 13 sasha.libreoffice 2012-02-06 01:01:25 UTC
@ Cedric
Please, see on comment 12
Comment 14 wepmaschda 2012-03-02 12:49:56 UTC
(In reply to comment #12)
> From outside, copying the implementation from LO-Draw to LO-Writer doesn't seem
> to be much work. I haven't looked into the code yet. Is there someone who can
> really estimate, how much effort it will be to port this from LO-Draw to
> LO-Writer? Is it worth to create a build environment etc.?

I looked a bit into the code:

First of all, a crop button can be added to writer by editing 

(draw) http://cgit.freedesktop.org/libreoffice/core/tree/sw/uiconfig/swriter/toolbar/graphicobjectbar.xml

similar to

(writer) http://cgit.freedesktop.org/libreoffice/core/tree/sw/uiconfig/swriter/toolbar/graphicobjectbar.xml


The button is then always deactivated and further editing is needed.

The files

(draw) http://cgit.freedesktop.org/libreoffice/core/tree/svx/source/tbxctrls/grafctrl.cxx
and
(writer) http://cgit.freedesktop.org/libreoffice/core/tree/sw/source/ui/shells/grfsh.cxx

are quite similar.

There are blocks labeled "SID_ATTR_GRAF_CROP" in SvxGrafAttrHelper::ExecuteGrafAttr() and SvxGrafAttrHelper::GetGrafAttrState() in the first file. 

The corresponding functions SwGrfShell::ExecAttr() and SwGrfShell::GetAttrState() in the second file have quite similar structure but have different number of parameters. If I just copy the Crop-blocks from draw to writer there are a lot of errors of course.


Is there somebody who knows how to translate the draw-part into the writer-part? Is translating draw into writer the correct approach or shouldn't writer and draw use about the same functions when handling graphics?

Is there some further work to do that I missed?
Comment 15 sasha.libreoffice 2012-03-02 22:08:18 UTC
@ wepmaschda@gmx.net
Thanks for investigating office internals

> Is there some further work to do that I missed?
Try ask here:    irc://chat.freenode.net/libreoffice-dev

About version: it should indicate most old version of office where bug appears for developers can more easy find source of problem (by which patch bug added)
Comment 16 tommy27 2012-03-16 13:17:02 UTC
have you ever tried the CropOOo extension?

http://aoo-extensions.sourceforge.net/en/project/cropooo
Comment 17 wepmaschda 2012-03-16 15:12:28 UTC
(In reply to comment #16)
> have you ever tried the CropOOo extension?
> 
> http://aoo-extensions.sourceforge.net/en/project/cropooo

Oh! It works in Writer! The description says "This extension provide an easy way to crop images in Draw or Impress." but after installing I have an icon also in writer and it works! 

It's just a bit weird that you have to press Enter for applying the crop. Do you know if it's still developed and if this can be fixed (applying the crop after mousebutton is released)?
Comment 18 Peter Stolz 2012-03-30 11:12:56 UTC
The CropOOo extension is not a good solution and their is no development since 2007. 

The disadvantages and problems:

UNDO (ctrl-z) doesn't seem to work right. So you have only one trial to crop.
To cancel the changes I had made and close the document to undo the crop.

When cropping a picture, after pressing Enter, the left and top offset is incorrect, and CropOOo adds margin as big as the graphic's distance to the top-left corner of the current page.

Even when I move the picture to the top-left of the page (using Anchor To Page), the picture's dimension is not changed by CropOOo, leaving white space around the graphic.
Comment 19 Roman 2012-03-31 09:47:32 UTC
I completely agree with Peter Stolz. Meanwhile plugin can be a temporary replacement but definitely not a solution.
Comment 20 jon 2012-05-08 02:09:26 UTC
If i had the time and skills, I would look into the code and try to fix this. Now i instead work with the swedish translation. Anyway: THIS IS IMPORTANT! Trying to convince people to switch from MSO to LO works fine until they try to crop an image, it is totally embarrassing to show them how to do it in writer.

Please update the bug if any progress is made!
Comment 21 Roman 2012-06-15 04:59:30 UTC
Why not include it in upcoming 3.6 release?
Comment 22 Rainer Bielefeld Retired 2012-12-02 08:30:46 UTC
This is an enhancement request, so improbable that it can be a MAB, I remove that relation.

We should not limit that feature to raster graphics and Writer, should also be available for vector graphics (wmf) in other applications (Calc)

@Thorsten:
Might be an EasyHack because the code already exists fro DRAW?
Comment 23 Thorsten Behrens 2012-12-13 15:58:54 UTC
Yeps, and with code pointers already. Though not a trivial exercise.
Comment 24 Werner 2012-12-25 10:12:10 UTC
*** Bug 58682 has been marked as a duplicate of this bug. ***
Comment 25 Sara Del Rey 2013-01-12 22:48:18 UTC
I am pleased with libreoffice, but I am agree with you in having a crop tool in writer. I think it would be more usefull, and a fast, easy way to crop images for people who usually add images to their texts. I hope to see this tool implemented soon. 

Thanks for help and work =)
Comment 26 Roman 2013-02-02 20:42:44 UTC
It's useless to wait. Two years passed, many duplicate tickets have been opened, we are still there.
Comment 27 ermplerc 2013-02-07 20:17:00 UTC
Hi,

I know it's not really productive to moan in bug reports, but you might want to take a look at the second paragraph in http://blogs.technet.com/b/office2010/archive/2010/02/01/office-2010-improvements-for-cropping-pictures.aspx

In particular "Cropping was overwhelmingly the most-used bit of editing used on pictures, so one of the first things we started work on was making cropping an easier-to-use and more powerful tool."

That matches my experience, but that assessment is obviously backed by tons of telemetry data from millions of users.

I'm not really advocating for the grey-out style of cropping (in my opinion it was a regression rather than an improvement), but visual cropping of any kind is a very important feature.
Comment 28 Thorsten Behrens 2013-02-08 13:10:21 UTC
(In reply to comment #27)
> I know it's not really productive to moan in bug reports, but you might want
> to take a look at the second paragraph in
> http://blogs.technet.com/b/office2010/archive/2010/02/01/office-2010-
> improvements-for-cropping-pictures.aspx
> 
This is marked as an easy hack, code ptrs are available - we'd gladly mentor someone willing to tackle this. It could be you - or someone you know!
Comment 29 Marcos Souza 2013-05-02 03:31:29 UTC
Maybe I can try this!

I believe this is more easy than solving a great issue, so if you guys could guide me, maybe I can help :)

I'm looking at code pointers now!
Comment 30 tommy27 2013-05-03 05:21:27 UTC
@Marcos Souza

there's already a guy working on this (Philippe Jung) who recently posted a message on the Dev mailing list.

I told him to get in touch. maybe you can help him
Comment 31 Pedro 2013-07-30 13:24:13 UTC
Are there any developments in getting a crop button in Writer?
Comment 32 Björn Michaelsen 2013-10-04 18:47:03 UTC
adding LibreOffice developer list as CC to unresolved EasyHacks for better visibility.

see e.g. http://nabble.documentfoundation.org/minutes-of-ESC-call-td4076214.html for details
Comment 33 Jorendc 2013-10-15 19:28:48 UTC
*** Bug 70482 has been marked as a duplicate of this bug. ***
Comment 34 Cédric Bosdonnat 2014-01-20 09:00:34 UTC
Restricted my LibreOffice hacking area
Comment 35 wayne 2014-03-27 11:13:55 UTC
I have just found this one! relatively new to Linux and LO and finding things as I need to use one.
Really, I'm shocked at the lack of a cropping tool. This is busines critical functionality - try writing a training manual without it. Anyone evaluating a switch from MS office to LO will find this and it will immediately be a shop stopper. Amazed that is it taking so long to fix
Comment 36 tommy27 2014-03-27 11:38:21 UTC
(In reply to comment #35)
> ...
> Really, I'm shocked at the lack of a cropping tool. 
> ...
> Anyone evaluating a switch from MS office to LO will find this and it will immediately be a
> shop stopper. 

in the meantime you can add that missing function using the CropOOo extension which in compatible with LibO too.

http://aoo-extensions.sourceforge.net/en/project/cropooo
Comment 37 Samuel Mehrbrodt 2014-03-29 11:02:03 UTC
*** Bug 48324 has been marked as a duplicate of this bug. ***
Comment 38 Stéphane Champeau 2014-03-29 11:09:03 UTC
Hi, bug #61991 seem duplicate this one
Comment 39 tommy27 2014-03-29 16:48:39 UTC
*** Bug 61991 has been marked as a duplicate of this bug. ***
Comment 40 Tim Deaton 2014-04-01 02:45:19 UTC
Issue 61991 is only partially a duplicate of this one.  This issue has dealt exclusively with adding a cropping tool to Writer.  Issue 61991 (and 74099, which I created and which was marked as a duplicate of 61991) deal with that AND with adding the same capability to Calc. 

Because of that, and because of Bjorn's comment (in 61991) about "writing a short rationale", I decided to copy my statement from issue 74099 below.

--- copied from 74099 & 61991 ---
I have long found that when I need to print something from the computer screen, the easiest way to do it was to hit PrintScreen, then paste it into an Excel spreadsheet, then crop and resize it till I have what I want.  For instance, I frequently want to crop & overlay two Google Maps screenshots so they fit together.  Or save an entire year of cropped screenshots of payroll tax confirmation screens on the same spreadsheet page.  (For me, Excel does these things far more easily than Word or Paint.)

For years I've occasionally tried the same thing using first OpenOffice Calc 3.x and now LibreOffice 4.0.x, and found that it is much more difficult.  Calc brings up a window with measurements you can change, and its own small snapshot of the graphic that shows where you are moving the borders to.  It works, but it is hard to get it just right.  You cannot see it well, and must repeatedly invoke the tool, change the measurements, and quit the tool to see what you've really got.  It takes several iterations to get it where you want it.

Excel's cropping tool (at least as far back as Excel 97) allows the mouse to grab the handles on the graphic's edges and drag them where you want them, which is far easier both to see and to do.

PLEASE add a mouse tool that can be used directly on the image in the spreadsheet.  The cropping icon could still bring up the window (for those who prefer it), and then a button in that window could replace the window with the mouse tool.
--- end of copy ---

Thanks,
Tim
Comment 41 wayne 2014-04-03 16:12:34 UTC
(In reply to comment #36)
> (In reply to comment #35)
> > ...
> > Really, I'm shocked at the lack of a cropping tool. 
> > ...
> > Anyone evaluating a switch from MS office to LO will find this and it will immediately be a
> > shop stopper. 
> 
> in the meantime you can add that missing function using the CropOOo
> extension which in compatible with LibO too.
> 
> http://aoo-extensions.sourceforge.net/en/project/cropooo


thanks. I tried installing this and did so successfully, but it doesn't seem to have done anything. There is no crop tool visible in the drawing tools, nor by right clicking on the image I need to crop. Am I doing something sill here?
Comment 42 tommy27 2014-04-03 16:30:21 UTC
@Wayne
you should see it's icon under "Tools/addons"
Comment 43 wayne 2014-04-05 10:28:21 UTC
thanks - I can see it now! That will mitigate the issue I think, but I still think this should standard functionality within Writer. Thanks again.
Comment 44 Pedro 2014-09-29 12:10:51 UTC
Created attachment 107061 [details]
Image showing the crop tool on Impress and not on Writer

This bug still hasn't been corrected...
Comment 45 Adolfo Jayme 2014-09-29 20:06:35 UTC
(In reply to comment #44)
> This bug still hasn't been corrected...

When you do not see activity on a bug, you can assume that it is not being worked on currently. There is no need to spam everyone with constant reminders, which will not speed up your request - unless you pay someone, of course.
Comment 46 Sushil Shinde 2014-09-30 12:30:01 UTC
If anyone is not working on this ... then can I take this issue.. ?
If possible also provide me more code pointers to add crop option in manu bar and to make it clickable..
Comment 47 Barry Broom 2014-09-30 16:17:46 UTC
Hi Sushil,

I only got as far as figuring out how to add a crop button to the relevent toolbar. I did not get an event to fire to run some code after the button was pressed. You will need to edit this XML file for the toolbar. It's pretty easy to understand: /core/sw/uiconfig/swriter/toolbar/graphicobjectbar.xml.

Since my son was born I don't have any free time to write code. Best of luck! I have assigned the bug to 'default' so you can take it. Cheers.
Comment 48 Pedro 2014-10-01 13:12:21 UTC
(In reply to comment #45)
> (In reply to comment #44)
> > This bug still hasn't been corrected...
> 
> When you do not see activity on a bug, you can assume that it is not being
> worked on currently. There is no need to spam everyone with constant
> reminders, which will not speed up your request - unless you pay someone, of
> course.

It appears that my comment sparked people to look at this issue. So no I am not spamming - just bringing it to attention.
Comment 49 Beluga 2015-01-13 17:49:19 UTC
*** Bug 88363 has been marked as a duplicate of this bug. ***
Comment 50 Laurent Charrière 2015-01-23 18:48:20 UTC
(In reply to wepmaschda from comment #14)
> The files
> 
> (draw)
> http://cgit.freedesktop.org/libreoffice/core/tree/svx/source/tbxctrls/
> grafctrl.cxx
> and
> (writer)
> http://cgit.freedesktop.org/libreoffice/core/tree/sw/source/ui/shells/grfsh.
> cxx
> 
> are quite similar.
> 
> There are blocks labeled "SID_ATTR_GRAF_CROP" in
> SvxGrafAttrHelper::ExecuteGrafAttr() and
> SvxGrafAttrHelper::GetGrafAttrState() in the first file. 

So I started looking into this, and I think that SID_ATTR_GRAF_CROP is used when cropping with the dialog, but I don't think it's used when doing an interactive crop. I added debug statements here and there when doing a crop in Draw, and the relevant SID is SID_OBJECT_CROP. Unfortunately this is not used in Writer. I'm able to add a new 'Crop Image' option in the context menu for inserted images in Writer, but then the problem becomes that Writer and Draw don't seem to use the same data structure to insert graphics, and it looks like only the one in Draw supports interactive crop. Details follow:

In Draw, once SID_OBJECT_CROP is sent, eventually what happens is that FuSelection::Activate() sets the drag mode SDRDRAG_CROP on mpView. SdrMarkView::SetDragMode get called. In turns, it calls SdrMarkView::SetMarkHandles(). In that method, there is to test to see if pMarkedObj is an instance of SdrGrafObj. When true, the instance of SdrGrafObj is responsible for "handling crop" (according to the comments). This is true in Draw, but not in Writer. In Writer, pMarkedObj is a SwVirtFlyDrawObj.

I'm stuck at this point. I don't know how to make the SwVirtFlyDrawObj draw the crop handles. Interestingly enough, while the handles are not drawn, the corner of an inserted image are draggable, and the cursor is changed to the cropping cursor. But there is no visible cropping taking place as in Draw.

As a side note, OpenOffice.org has a whole page devoted to an ongoing refactoring of Writer's usage of the Drawing layer at https://wiki.openoffice.org/wiki/Refactoring_of_Writer%27s_usage_of_the_Drawing_layer. I think this may be related.

I would appreciate any pointers on how to keep proceeding with this bug.
Comment 51 Philippe Jung 2015-01-23 22:45:30 UTC
Hello,
I tried to work on this bug last year and I had something nearly working. But, during this time, the code base changed (a lot) and I have no time for the moment to rework it. So I would like to share what I found. I will attach the patch "as is" to this ticket. It is not working at all with current trunk.

Basically, you have to use a virtual NbcCrop function on a parent that is common to SwVirtDraw and SdrGraph

I am not going to detail every change I made in this ticket. Please read the patch and if you have any question feel free to ask.

The crop code was in SdrDragCrop::EndSdrDrag. You have to move this code in SdrGraphObj. Now in SdrDragCrop::EndSdrDrag call the crop virtual => getSdrDragView().CropMarkedObj

Now the problems I am facing:
1) cropping code has changed a lot in EndSdrDrag. Mine uses the old code. You will have to adapt it
2) Regarding links, you can also consider Armin Le Grand web page  https://wiki.openoffice.org/wiki/Aw080_documentation. This explains the mathematical logic using transformation matrixes (If you "git blame" the cropping code, this will point to "alg"). If I am not mistaken, these changes come from evolution of OpenOffice merged into Libre Office.
3) I tried to contact alg and his advice is "I would suggest to *not* touch SwVirtFlyDrawObj at all, it's dead code. It's a kind of proxy, try to get the original SdrObject from it and modify that instead. Or better: just tunnel your call to the original object."

Philippe
Comment 52 Philippe Jung 2015-01-23 22:47:02 UTC
Created attachment 112751 [details] [review]
A patch that nearly worked but cannot be applied on current trunk

This patch relates to the previous comment


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.