BezierCusps Property
BezierCusps Property |
Gets an array that contains the indices of the cusps of the Bezier approximation of the stroke.
Declaration
[C++]
[propget] HRESULT get_BezierCusps ([out, retval] VARIANT* BezierCusps);
[Microsoft® Visual Basic® 6.0]
Public Property Get BezierCusps() As Variant
Property Value
VARIANT An array of integers for the indices of the points that are the cusps of the Bezier approximation of the stroke.
This property is read-only.
For more information about the VARIANT structure, see Using the Automation Library.
Return Value
HRESULT value | Description |
---|---|
S_OK | Success. |
E_POINTER | Parameter pointer was NULL or invalid. |
E_OUTOFMEMORY | Cannot allocate memory for the points. |
E_INK_EXCEPTION | An exception occurred inside the method. |
Remarks
Note: The array of Bezier control points that the BezierPoints property returns are made up of x and y values. The BezierCusps property refers only to the x values in this array. The y values can be retrieved by an action similar to the following below.
A cusp is a point on the stroke where the direction of writing changes in a discontinuous fashion. For example, if the stroke represents the capital letter "L", this property returns three cusps: two corresponding to the first and last control points on the stroke and the third representing the corner of the "L".
The following code extracts the x and y values of the Bezier cusps of an IInkStrokeDisp, theStroke, and stores them in a two-dimensional array called BezierCuspValues.
'Store the cusps in an array
Dim TheCusps As Variant
TheCusps = theStroke.BezierCusps
'Create a dynamic array to hold the cusp point values
Dim BezierCuspValues As Variant
ReDim BezierCuspValues(UBound(theCusps), 1)
'Populate the dynamic array with the actual cusp point values
For i = 0 To UBound(TheCusps)
BezierCuspValues(i, 0) = theStroke.BezierPoints(2 * theCusps(i))
BezierCuspValues(i, 1) = theStroke.BezierPoints(2 * theCusps(i) + 1)
Next
Example
[Visual Basic 6.0]
This Visual Basic 6.0 example demonstrates displaying several kinds of information that is recorded with each IInkStrokeDisp object. The calling program uses menu items to toggle the display of each strokes points, Bezier points, Bezier cusps, and self-intersections. The InkRenderer object's InkSpaceToPixelFromPoints method is used to convert the points for display. The LocatePoint function is used to interpolate the locations of the self-intersections. This example starts with a Standard exe application and adds a reference to the Microsoft Tablet PC Type Library, and adds a menu with menu items including MenuFileExit, MenuDemoAllPoints, MenuDemoCusps, MenuDemoPoints, and MenuDemoSelfIntersections.
Option Explicit
Option Base 0
Dim WithEvents theInkCollector As InkCollector
Private Sub Form_Load()
Me.ScaleMode = vbPixels
Set theInkCollector = New InkCollector
theInkCollector.hWnd = Me.hWnd
theInkCollector.Enabled = True
End Sub
Private Sub Form_Paint()
Dim i As Integer
Dim theStrokes As InkStrokes
Set theStrokes = theInkCollector.Ink.Strokes
Dim theStroke As IInkStrokeDisp
For Each theStroke In theStrokes
Dim ptBezierPoints() As Long
ptBezierPoints = theStroke.BezierPoints
Dim ptStrokePoints() As Long
ptStrokePoints = theStroke.GetPoints()
theInkCollector.Renderer.InkSpaceToPixelFromPoints Me.hDC, ptBezierPoints
theInkCollector.Renderer.InkSpaceToPixelFromPoints Me.hDC, ptStrokePoints
If MenuDemoCusps.Checked Then
Dim theCusps() As Long
theCusps = theStroke.BezierCusps
For i = 0 To UBound(theCusps)
'Draw a little rectangle around each Bezier cusp.
Dim cuspX As Long
Dim cuspY As Long
cuspX = ptBezierPoints(theCusps(i) * 2)
cuspY = ptBezierPoints(theCusps(i) * 2 + 1)
Line (cuspX - 2, cuspY - 2)-Step(5, 5), vbRed, B
Next
End If
If MenuDemoPoints.Checked Then
For i = 0 To UBound(ptBezierPoints) Step 2
'Draw a little diagonal line up from each Bezier point.
Line (ptBezierPoints(i), ptBezierPoints(i + 1)) _
-Step(4, -4), vbBlue
Next
End If
If MenuDemoAllPoints.Checked Then
For i = 0 To UBound(ptStrokePoints) Step 2
'Draw a little diagonal line down from each point.
Line (ptStrokePoints(i), ptStrokePoints(i + 1)) _
-Step(-4, 5), vbMagenta
Next
End If
If MenuDemoSelfIntersections.Checked Then
Dim theSelfIntersectionLocationsArray() As Single
theSelfIntersectionLocationsArray = theStroke.SelfIntersections
Dim theSelfIntersectionLocation As Variant
For Each theSelfIntersectionLocation In theSelfIntersectionLocationsArray
Dim pt() As Long
pt = LocatePoint(theStroke, theSelfIntersectionLocation)
theInkCollector.Renderer.InkSpaceToPixel Me.hDC, pt(0), pt(1)
'Draw a little circle around each intersection.
Circle (pt(0), pt(1)), 7, vbRed
Next
End If
Next
End Sub
Private Sub MenuDemoAllPoints_Click()
MenuDemoAllPoints.Checked = Not MenuDemoAllPoints.Checked
Refresh
End Sub
Private Sub MenuDemoCusps_Click()
MenuDemoCusps.Checked = Not MenuDemoCusps.Checked
Refresh
End Sub
Private Sub MenuDemoPoints_Click()
MenuDemoPoints.Checked = Not MenuDemoPoints.Checked
Refresh
End Sub
Private Sub MenuDemoSelfIntersections_Click()
MenuDemoSelfIntersections.Checked = _
Not MenuDemoSelfIntersections.Checked
Refresh
End Sub
Private Sub MenuFileExit_Click()
Unload Me
End Sub
'This function returns the approximate point along
'a stroke represented by a Single, as a Point.
Private Function LocatePoint( _
ByVal theStroke As IInkStrokeDisp, _
ByVal theFIndex As Single) As Long()
Dim theResult(1) As Long
'Get the two nearest points to the point of interest.
Dim ptStrokePoints() As Long
ptStrokePoints = theStroke.GetPoints(Int(theFIndex), 2)
If UBound(ptStrokePoints) < 2 Then
'This must be an end point.
theResult(0) = ptStrokePoints(0)
theResult(1) = ptStrokePoints(1)
Else
'Get fractional part to interpolate the distance
'between the points.
Dim theFraction As Single
theFraction = theFIndex - Int(theFIndex)
Dim deltaX As Integer
deltaX = _
CInt((ptStrokePoints(2) - ptStrokePoints(0)) * theFraction)
Dim deltaY As Integer
deltaY = _
CInt((ptStrokePoints(3) - ptStrokePoints(1)) * theFraction)
'Return the interpolated point.
theResult(0) = ptStrokePoints(0) + deltaX
theResult(1) = ptStrokePoints(1) + deltaY
End If
LocatePoint = theResult
End Function
Private Sub theInkCollector_Stroke( _
ByVal Cursor As MSINKAUTLib.IInkCursor, _
ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, _
Cancel As Boolean)
Refresh
End Sub