OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 16-04-2007, 03:37
squonk
Guest
 
Posts: n/a
Default Problems extracting curves from text

Hi all,

I'm having a few problems trying to extract curves from a Corel DRAW text object in a C++ code.

Code:
CorelDRAW::IDrawShapePtr shape; 
…
// By now I know that shape is of cdrTextShape type
shape -> ConvertToCurves ();
CorelDRAW::IDrawCurvePtr curve = shape -> Curve;

CorelDRAW::IDrawSubPathsPtr subPaths = curve -> SubPaths;
long numSubPaths = subPaths -> Count;
for (long subPathIdx = 1; subPathIdx <= numSubPaths; subPathIdx ++)
{
	CorelDRAW::IDrawNodesPtr nodes = subPath -> Nodes;
	long numNodes = nodes -> Count;
	for (long nodeIdx = 1; nodeIdx <= numNodes; nodeIdx ++)
	{
		CorelDRAW::IDrawNodePtr node = nodes -> Item [nodeIdx];
		double startPosX  = node -> Segment -> StartingControlPointX;
	}
}
Obviously the code does more than just obtaining the starting control point for each segment, but I’ve omitted that as irrelevant.
Actually the code above works just fine with one important exception: evidently Shape::ConvertToCurves() modifies the shape, so shape is no longer a text after calling this function! And I need it to stay the text… hence Problem 1:

Problem 1. I’ve tried to produce a shape clone first, and then convert it to curves:

Code:
CorelDRAW::IDrawShapePtr clone = shape -> Clone (0, 0);
clone -> ConvertToCurves ();
However the line double startPosX = node -> Segment -> StartingControlPointX; throws the E_INVALIDARG exception then. Note that some other functions of Segment still work OK (e.g. Segment::Type property), meaning that the Segment instance must be valid in some sense.
Nor Shape :: DisplayCurve works (instead of ConvertToCurves+Curve): it throws the E_NOINTERFACE exception.

Problem 2. If the text is multi-colored (i.e. some letters have different color than others), then even the original code above (with no cloning) does not work: the line CorelDRAW::IDrawCurvePtr curve = shape -> Curve; throws the E_NOINTERFACE exception.

TIA
Reply With Quote
  #2  
Old 16-04-2007, 23:11
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,932
Blog Entries: 4
Default

Ok, let me answer your questions in sequence.

Yes, Shape::ConvertToCurves does change the type of the object. It does exactly what "Arrange > Convert To Curves (Ctrl+Q)" command does in the menu. When you do that, the object becomes the curve.

If you want to create a temporary object, you might just duplicate it and then delete the copy when you are done:

Code:
CorelDRAW::IDrawShapePtr sCopy = shape->Duplicate(0, 0);
sCopy->ConvertToCurves();
sCopy->Curve->...
sCopy.Delete
Now the second problem. Segment::StartingControlPointX is valid only for curve segments. If your first segment happens to be a line segment, you can't get the control points, since it has none. You still can call Segment::StartingControlPointAngle to get the direction of the line, but all other control point properties are invalid for line segments.

The third problem of multicolored text. This is a side effect of convert to curves. When you convert a text object that has individual characters with different fills/outlines, it can no longer create a single curve that still retains those attributes (you can't have one path with one fill and another with some other fill). In order to work correctly, CorelDRAW's Convert To Curves command, creates several curves, each with its unique fill/outline attributes. And the result is grouped. So, when you convert a text object with various fills/outline, you'll end up with a group of curves.

You can easily test for this by inspecting Shape::Type properties and ensuring it is cdrCurveShape and not cdrGroupShape. If it is a group, you can go through the individual shapes in the Shapes collection:

Code:
if( sCopy->Type == CorelDRAW::cdrGroupShape)
{
  for(int idx = 1; idx <= sCopy->Shapes->Count; idx++)
  {
     CorelDRAW::IDrawShapePtr sCurve = sCopy->Shapes->Item[idx];
     // ... do your stuff with the current curve
   }
}
And finally, Shape.DisplayCurve doesn't work for text, as you have already discovered.
Reply With Quote
  #3  
Old 17-04-2007, 01:47
squonk
Guest
 
Posts: n/a
Default

Thank you very much Alex.

Meanwhile I’ve achieved what I needed by first breaking apart text shapes, then doing my stuff and finally undoing the break aparts. But your solution is better (of course!)

Incidentally, I was using Segment :: StartingControlPointX only for cdrCurveSegment-type segments and it was still crashing. Anyway, now it’s of no importance.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Striping a word down to the first letter only knowbodynow CorelDRAW/Corel DESIGNER VBA 9 19-04-2007 15:14
Adding text via VBA knowbodynow CorelDRAW/Corel DESIGNER VBA 2 03-03-2006 09:15
Text selection and sizing ddonnahoe CorelDRAW/Corel DESIGNER VBA 5 17-05-2005 13:19
format text dialog box implement graphicdesigner CorelDRAW/Corel DESIGNER VBA 5 22-12-2004 13:37
Reset text after text compression. Bellekom CorelDRAW/Corel DESIGNER VBA 2 05-05-2004 06:14


All times are GMT -5. The time now is 03:08.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com