Issue 115096

Summary: filter: apple(pict): a proposition to draw thick lines/frames
Product: General Reporter: osnola <alonso>
Component: codeAssignee: wolframgarten
Status: CLOSED FIXED QA Contact: issues@framework <issues>
Severity: Trivial    
Priority: P3 CC: hdu, issues
Version: OOo 1.0.0   
Target Milestone: 3.4.0   
Hardware: Mac   
OS: All   
Issue Type: PATCH Latest Confirmation in: ---
Developer Difficulty: ---
Attachments:
Description Flags
the proposed patch
none
some pictures which contain some lines/frames
none
a pict where the result is <<worse>> than previously ( because of the clipping )
none
a pict to illustrate << my spline bug>> ( each corner is composed of an unique spline curve)
none
the new proposed patch
none
the new problematic pictures
none
a zoom of the small arc none

Description osnola 2010-10-17 10:11:40 UTC
Actually, ipict.cxx draws the line and the shapes frame without using the pen size information 
(ie. it uses always a 1 pixel width to draw the curve ). A proposition to draw the line and the shape
with thickness.

Notes: 
- the shapes are now transformed in B2DPolygon ( which is in module basegfx ), 
   so if filter CAN NOT DEPENT on basegfx, this proposition must be DISCARDED,
- this patch CAN ONLY BE APPLIED AFTER applying http://www.openoffice.org/nonav/issues/showattachment.cgi/72019/ipict3.cxx.patch 
( from http://www.openoffice.org/issues/show_bug.cgi?id=115029 )
- I have replaced circle/arc by cubic splines in order to represent them by a BD2Polygon ( using 
    the same method than in http://whizkidtech.redprince.net/bezier/circle/ ),  so their representations
   are no longer exact,
- as the methods to draw the shape in OpenOffice are not the same than the Quickdraw routines, I try to do some compromises between 
   drawing the <<exact>> Apple Pict shapes using a complex representations and drawing a approximated simple
   shapes,
- in general, the obtained results seem better (ie. more faithful) than previously ( using my database of pictures), but
I found a few Apple Pict where the opposite can be said ( mainly because some clipping regions are too big),
- I add a note to explain the region format, but I do not add code because I do not know how to draw these regions.

- I note a small bug when drawing some spline curves with small curvature radius, some cracks happen in the drawing ( but
maybe it is limited to my version of OpenOffice ) and another one when drawing some basic B2DPolygon (ie. a little square 
in each corner is not drawn correctly ),
- in the files' attachment, the original pict files will have extension .pict, their quickdraw representations will have extension .pict.tiff
and the extension .pict.ascii correspond to a homemade parsing...
Comment 1 osnola 2010-10-17 10:12:25 UTC
Created attachment 72077 [details]
the proposed patch
Comment 2 osnola 2010-10-17 10:14:54 UTC
Created attachment 72078 [details]
some pictures which contain some lines/frames
Comment 3 osnola 2010-10-17 10:17:35 UTC
Created attachment 72079 [details]
a pict where the result is <<worse>> than previously ( because of the clipping )
Comment 4 osnola 2010-10-17 10:19:04 UTC
Created attachment 72080 [details]
a pict to illustrate << my spline bug>> ( each corner is composed of an unique spline curve)
Comment 5 philipp.lohmann 2010-11-15 12:10:07 UTC
assign to owner

@sj: please have a look
Comment 6 sven.jacobi 2010-11-25 15:46:19 UTC
sj->osnola: Your patch looks nice, but I have to note that we have a loot of
helper functions in basegfx which are working with the same principle as in your
patch. Please have a look at
ooo/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx: createPolygonFromEllipse or
createPolygonFromEllipseSegment.

Is it possible that you change your patch to use the basegfx toolkit ? 
Comment 7 osnola 2010-11-26 07:19:40 UTC
Using createPolygonFromEllipse, createPolygonFromEllipseSegment, createPolygonFromRect seem 
effectively a good idea and will probably simplify the code. 

I will try to give some news next week ( ie. because of the last java update 1.6.0_22, my sources of 
OpenOffice no longer compile ; so before doing any test, I will need first to get again a working version, 
which may take some time :-~ ).
Comment 8 osnola 2010-11-29 11:08:13 UTC
So a new version which uses the functions of b2dpolygontools which indeed simplifies a lot the code.

The result between this version and the previous one seem quite similar except that in some case where b2dpolygontools seems to generate odd splines. Therefore I will also attach pict.bugs which 
contains two examples which seem to err a lot with the following extensions:
- .pict: the original picture,
- .pict.ascii: the picture parsing,
- .pict.tiff: the quickdraw result,
- .pict.old.png: my previous result when I generated by hand the splines,
- .pict.new.png: the new result obtained with b2dpolygontools functions with a red grid to show coordinates.

	I dig a little to understand what happens:
For Image280, the small arc around O does not look like a arc ; for the three arcs around O, the program constructs a B2DPolygon by calling
	<< tools::createPolygonFromEllipseSegment(Pt, dim[0], dim[1], angl[0], angl[1]);>> with
      		Arc: Pt=21x210, dim=62x62, angl=5.60251x1.74846e-07 // Ok, the intermediate arc
      		Arc: Pt=20x210, dim=89x89, angl=5.27089x5.61996       // Ok, the biggest arc
      		Arc: Pt=21x208, dim=56x56, angl=5.67232x0.0174534  //  the small arc which seems bugged
For Image7239, there must be two ellipses (*) around B and J ; in these case, 
          the program constructs the B2DPolygon by calling  <<tools::createPolygonFromRect(Rect, 1., 1.); >> with
		RoundRect: Rect=125x33<->143x56 // ellipse around B
	      	RoundRect: Rect=44x92<->61x113 // ellipse around J
so I guess that the problem was in b2dpolygontools, but I did not have time to dig further....

(*) in fact, the picture asks to clear two round rectangles with maximum round corners, which is a complicated way to define an ellipse....
Comment 9 osnola 2010-11-29 11:09:00 UTC
Created attachment 75159 [details]
the new proposed patch
Comment 10 osnola 2010-11-29 11:10:15 UTC
Created attachment 75160 [details]
the new problematic pictures
Comment 11 sven.jacobi 2010-11-29 16:30:29 UTC
sj->osnola: Many thanks for your help and reworking your previous patch, it
looks really good now. Your patch has been applied to cws[impress204] for OOo 3.4

I think the remaining problems with the arc can be traced back to 
void OutputDevice::DrawPolyLine where a conversion from b2dpolygon with double
precision to a tools polygon with integer precision takes place.

This problem should be fixed automatically when activating the new
MetaB2DPolyLineAction (but I don't know when this happens).

Another fix could be to scale the b2dpolygon before drawing, so that the
conversion from double to int polygon isn't as lossy as it is now (the
corresponding MapMode needs to be set to the device then)


Comment 12 osnola 2010-11-30 11:37:54 UTC
> Many thanks for your help and reworking your previous patch
No problem ; as these b2dpolygontools functions exist, it was quite natural to rewrite the patch to use them...

> I think the remaining problems with the arc can be traced back to 
> void OutputDevice::DrawPolyLine where a conversion from b2dpolygon with double
> precision to a tools polygon with integer precision takes place.

I dig a little more, and indeed the problem seems to come from OutputDevice::DrawPolyLine but I am not sure that the problem comes only from the double to 
int conversion:

Ie. For the  Arc: Pt=21x208, dim = 56x56, angl = 5.67232x0.0174534
 b2dpolygontools generates the Polygon (*): 
       Pt0:pos = 66.8725x175.88, prev = _, next = 67.858x177.287
       Pt1:pos = 69.4974x180, prev = 68.6383x178.512, next = 74.6521x188.928
       Pt2:pos = 77x208, prev = 77x197.691, next = 77x208.344
       Pt3:pos = 76.9915x208.977, prev = 76.9975x208.634, next = _
which seems correct ; I will attach a picture which zooms the problematic arc, where I have added:
   - in blue the segments from the previous control point to position
   - and in green the segments from position to the next control point 
with the basic coordinate grid alignment.

The picture made me think that OutputDevice::DrawPolyLine had used the next control point of Pt0 (instead of the previous control point of Pt1) to draw the 
second spline...

(*) where 
- pos is the point obtained by poly.getB2DPoint(i)
- prev is the point obtained by poly.getPrevControlPoint(i)
- next is the point obtained by poly.getNextControlPoint(i)
Comment 13 osnola 2010-11-30 11:38:51 UTC
Created attachment 75177 [details]
a zoom of the small arc
Comment 14 sven.jacobi 2010-12-06 12:44:21 UTC
Sorry, I was out of time last week. I added HDU as cc, he is more firm with our
polygons and he promised me to take care of your suspicion.

If this is a bug in our polygon conversion it needs to be fixed. 
Comment 15 osnola 2010-12-06 12:58:14 UTC
osnola->sj : Ok, no problem.

In fact, I found the problematic function and I opened a new issue : http://www.openoffice.org/issues/show_bug.cgi?id=115917 .

Comment 16 sven.jacobi 2010-12-14 15:05:00 UTC
sj->wg: to verify this issue, just compare the pictures of sample.zip with an
older version of OOo.
Comment 17 wolframgarten 2010-12-21 08:16:38 UTC
Verified in CWS.