Latest source merged from Syncfusion

This commit is contained in:
pipeline 2021-02-02 20:21:04 -08:00
Родитель b26aa350d1
Коммит 3bdec61259
2 изменённых файлов: 97 добавлений и 0 удалений

Просмотреть файл

@ -453,3 +453,33 @@ private void PdfViewer_AnnotationMovedOrResized(object sender, AnnotationMovedOr
{% endhighlight %}
{% endtabs %}
## How to render Ink strokes using custom ink points?
By default, ink strokes are drawn by recording the points on the screen traversed by the input device (stylus or finger). The quality of the strokes thus drawn may not be satisfactory as it considers only raw points. If needed, the points can be modified using any algorithms to smoothen the strokes.
When the ink session ends after drawing the strokes, the [InkAdded](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.SfPdfViewer.html#Syncfusion_SfPdfViewer_Android_SfPdfViewer_InkAdded) event will be raised. The [InkAnnotation](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.InkAnnotation.html) instance that is drawn on the page is exposed as sender argument of the [InkAdded](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.SfPdfViewer.html#Syncfusion_SfPdfViewer_Android_SfPdfViewer_InkAdded) event. We can get the Ink points which we drew on the page from [InkAnnotation.InkPointsCollection](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.InkAnnotation.html#Syncfusion_SfPdfViewer_Android_InkAnnotation_InkPointsCollection). The [InkPointsCollection](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.InkAnnotation.html#Syncfusion_SfPdfViewer_Android_InkAnnotation_InkPointsCollection) is of a type List<List<float>>. Each List<float> in this collection represents each stroke of the ink annotation we drew. There are as many List<float> instances in the [InkPointsCollection](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.InkAnnotation.html#Syncfusion_SfPdfViewer_Android_InkAnnotation_InkPointsCollection) as the number of strokes in the ink annotation.
The List<float> in turn, has the series of alternate X and Y coordinates of the ink stroke. i.e. the values at the odd position are X coordinates and at the even position are Y coordinates.
We can modify or add new stroke points in the [InkAnnotation.InkPointsCollection](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.InkAnnotation.html#Syncfusion_SfPdfViewer_Android_InkAnnotation_InkPointsCollection). As soon as the [InkAdded](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.SfPdfViewer.html#Syncfusion_SfPdfViewer_Android_SfPdfViewer_InkAdded) event handler completes execution, the modified points will be reflected in the ink annotation on the UI.
{% tabs %}
{% highlight c# %}
private void PdfViewerControl_InkAdded(object sender, InkAddedEventArgs args)
{
InkAnnotation inkAnnotation = sender as InkAnnotation;
List<List<float>> drawnPoints = inkAnnotation.InkPointsCollection;
//Modify the drawn ink points
List<List<float>> modifiedPoints = PerformModification(drawnPoints);
inkAnnotation.InkPointsCollection = modifiedPoints;
}
{% endhighlight %}
{% endtabs %}
N> The strokes cannot be smoothened when the user is drawing the strokes as the points are still being recorded. They can be smoothened only after the user confirms the end of the ink session.

Просмотреть файл

@ -249,5 +249,72 @@ private void PdfViewer_TextSelectionCompleted(object sender, TextSelectionComple
var pageBounds = args.PageBounds;
}
{% endhighlight %}
{% endtabs %}
## How to get the start index and end index of the selected text?
The completion of the text selection action would trigger the [TextSelectionCompleted](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.SfPdfViewer.html#Syncfusion_SfPdfViewer_Android_SfPdfViewer_TextSelectionCompleted) event. The event argument would contain details about the start index and end index of the selected text.
{% tabs %}
{% highlight c# %}
private void PdfViewerControl_TextSelectionCompleted(object sender, TextSelectionCompletedEventArgs args)
{
//Starting index of the selected text on the page.
int startIndex = args.SelectedTextStartIndex;
//Ending index of the selected text on the page.
int endIndex= args.SelectedTextEndIndex;
}
{% endhighlight %}
{% endtabs %}
N> The values of [SelectedTextStartIndex](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.TextSelectionCompletedEventArgs.html#Syncfusion_SfPdfViewer_Android_TextSelectionCompletedEventArgs_SelectedTextStartIndex) and [SelectedTextEndIndex](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.TextSelectionCompletedEventArgs.html#Syncfusion_SfPdfViewer_Android_TextSelectionCompletedEventArgs_SelectedTextEndIndex) properties correspond only to the text present in the page on which the text is selected.
## How to customize the text selection context menu?
By default, the text selection context menu contains built-in menu items such as Copy, Highlight, Underline, and Strikethrough. You can add additional items in the text selection context menu by creating an instance of type [TextSelectionMenuItem](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.TextSelectionMenuItem.html) and add the item to the [TextSelectionSettings.MenuOptions.Items](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.TextSelectionMenu.html#Syncfusion_SfPdfViewer_Android_TextSelectionMenu_Items) property.
As the type of this property is ObservableCollection, the following operations can be performed on the text selection context menu items.
1. Adding a new item
2. Clearing the menu items
3. Inserting a new item
4. Removing an existing item
Below code illustrates adding a new menu item to the text selection context menu.
{% tabs %}
{% highlight c# %}
TextSelectionMenuItem menuItem = new TextSelectionMenuItem();
//The text to display on the menu item
menuItem.Text = “Find text”;
//The ID to uniquely identify the menu item.
menuItem.Id = "find_text";
pdfViewer.TextSelectionSettings.MenuOptions.Items.Add(menuItem);
{% endhighlight %}
{% endtabs %}
### How to handle the click event of the menu item?
The [TextSelectionMenuItemClicked](https://help.syncfusion.com/cr/xamarin-android/Syncfusion.SfPdfViewer.Android.TextSelectionMenu.html#Syncfusion_SfPdfViewer_Android_TextSelectionMenu_TextSelectionMenuItemClicked) event is raised when any menu item is clicked. While performing the intended operation when a menu item is clicked, the selected text can be obtained as described in the [above](https://help.syncfusion.com/xamarin-android/sfpdfviewer/select-and-copy-text#how-to-acquire-selected-text) section.
{% tabs %}
{% highlight c# %}
private void PdfViewerControl_TextSelectionMenuItemClicked(object sender, TextSelectionMenuItemClickedEventArgs args)
{
TextSelectionMenuItem menuItem = sender as TextSelectionMenuItem;
switch(menuItem.Id)
{
//Perform the intended operation after identifying the menu item from its Id value.
}
}
{% endhighlight %}
{% endtabs %}