Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1e8ec24
Add annotations panel and highlighting to PDFViewer; Will include web…
kpence Oct 5, 2021
ef502b4
Change highlight color upon mouse hovering; Remove unneeded file
kpence Oct 6, 2021
6c6c0a4
Remove redundant code
kpence Oct 6, 2021
fc663d0
Add assets used for Annotations feature
kpence Oct 6, 2021
4760c78
Install annotation side panel html to config folder
kpence Oct 6, 2021
b38bef5
Remove unneeded file linking
kpence Oct 6, 2021
a5a83c1
Fix annotationSidePanel copy location and uri path in web browser source
kpence Oct 6, 2021
46779ea
Scroll to center of annotation in PDF and change its highlight color
kpence Oct 6, 2021
0abc1eb
Make the annotations sorted in the side panel based on where they app…
kpence Oct 7, 2021
4595c69
Add GridSplitter to Bookmark side panel to allow for resizing bookmar…
kpence Oct 16, 2021
2a17324
Clean up PDF annotation webbrowser script
kpence Nov 13, 2021
7c170f9
Replace Windows Control Webbrowser with Windows Forms Webbrowser
kpence Nov 13, 2021
ff15827
Configure Windows Registry to make PDF Annotation Web browser utilize…
kpence Nov 13, 2021
8b2e8cb
Undo changes to PDFPlugin
kpence Nov 13, 2021
15e6326
Update app manifest to force permission to modify registry
kpence Nov 13, 2021
a276a45
Add Windows hooks into annotation webbrowser for key input; Add annot…
kpence Nov 14, 2021
ef78b99
Remove unnecessary IE version registry changing code
kpence Nov 14, 2021
5e75182
Change annotation extract highlight color to light blue
kpence Nov 14, 2021
720f879
Add shortcut to opening annotation side panel
kpence Nov 14, 2021
4eb00de
Change AnnotationHighlights to using a dictionary that indexes by PDF…
kpence Dec 13, 2021
b994085
Make it so the highlighted text is the initial content for the annota…
kpence Dec 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions assets/annotationSidePanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<!DOCTYPE html>
<html>
<head>
<style>
.pdf-annotation-extraction {
background-color: lightblue;
}
</style>
</head>
<body>
<div id="root"/>
<script>
var timeoutHandle;
var selectedAnnotationId = 0;
function handleKeyPress(event) {
switch (event.keyCode) {
case 1:
document.execCommand('selectAll');
break;
case 2:
document.execCommand('bold');
break;
case 3:
document.execCommand('copy');
break;
case 9:
document.execCommand('italic');
break;
case 21:
document.execCommand('underline');
break;
case 22:
document.execCommand('paste');
break;
case 24:
document.execCommand('cut');
break;
case 26:
document.execCommand('undo');
break;
case 27:
document.execCommand('decreaseFontSize');
break;
case 29:
document.execCommand('increaseFontSize');
break;
}
request_update();
}
function getAnnotationIdFromElement(element) {
var firstRootSibling = element;
while (!firstRootSibling.id || firstRootSibling.id.substring(0,10)!= "annotation") {
firstRootSibling = firstRootSibling.parentElement;
}
var id = parseInt(firstRootSibling.id.replace("annotation",""));
return id;
}
function handleFocus(event) {
var id = getAnnotationIdFromElement(event.srcElement);
window.external.Annotation_OnFocus(id);
}
function handleClick(event) {
var id = getAnnotationIdFromElement(event.srcElement);
window.external.Annotation_OnClick(id);
}
function request_update() {
if (timeoutHandle != null) {
window.clearTimeout(timeoutHandle);
}
timeoutHandle = null;
timeoutHandle = window.setTimeout(update, 250);
}
function update() {
timeoutHandle = null;
window.external.Annotation_OnAfterUpdate();
}
function handleExtract() {
// TODO Consider making this compatible with any IE version
if (document.selection && document.selection.createRange) {
var range = document.selection.createRange();
if (range.htmlText && range.htmlText.length > 0) {
htmlText = range.htmlText;
range.pasteHTML("<SPAN class=\"pdf-annotation-extraction\">"+htmlText+"</SPAN>");
request_update();
window.external.Annotation_HandleExtract(htmlText);
}
}
}
function clearAnnotations() {
var e = document.getElementById("root");
while (e.firstChild) {
e.removeChild(e.firstChild);
}
}
function insertAnnotation(annotationId, sortingKey, text) {
var e = document.getElementById("root");
var onUpdate = "handleKeyPress(event)";
var onClick = "handleClick(event)";
var onFocus = "handleFocus(event)";
annotationId = "annotation"+annotationId;
var childHtml = "<div class=\"key"
+ sortingKey
+ "\" onkeypress=\""
+ onUpdate
+ "\" onclick=\""
+ onClick
+ "\" onfocus=\""
+ onFocus
+ "\" id=\""
+ annotationId
+ "\" border=\"1px solid black\" contenteditable>"
+ text
+ "</div><hr/>";
if (!e.firstChild) {
e.insertAdjacentHTML(
"beforeend",
childHtml
);
} else {
for (e = e.firstChild; e != null; e = e.nextSibling) {
var key = parseInt(e.className.replace("key",""));
if (parseInt(sortingKey) < key) {
e.insertAdjacentHTML(
"beforebegin",
childHtml
);
return;
}
}
e = document.getElementById("root");
e.insertAdjacentHTML(
"beforeend",
childHtml
);
}
}
function scrollToAnnotation(annotationId) {
var e = document.getElementById("annotation"+annotationId);
e.scrollIntoView();
e.focus();
}
</script>
</body>
</html>
Binary file added assets/images/icons/sideBarAnnotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#region License & Metadata

// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
//
// Created On: 2018/12/23 17:09
// Modified On: 2019/02/22 13:43
// Modified By: Alexis

#endregion




using Newtonsoft.Json;
using Patagames.Pdf.Net.Controls.Wpf;
using System;
using System.Collections.Generic;

namespace SuperMemoAssistant.Plugins.PDF.Models
{
public class AnnotationAddedEventArgs : EventArgs
{
public PDFAnnotationHighlight NewItem { get; set; }
}

public class PDFAnnotationHighlight : PDFTextExtract
{
#region Properties & Fields - Public

[JsonProperty(PropertyName = "HTML")]
public string HtmlContent { get; set; }
[JsonProperty(PropertyName = "AnnotationId")]
public int AnnotationId { get; set; }

#endregion




#region Methods
public static implicit operator PDFAnnotationHighlight(SelectInfo selInfo)
{
return new PDFAnnotationHighlight
{
StartPage = selInfo.StartPage,
StartIndex = selInfo.StartIndex,
EndPage = selInfo.EndPage,
EndIndex = selInfo.EndIndex,
HtmlContent = "<div></div>",
AnnotationId = 0
};
}

public static PDFAnnotationHighlight Create(SelectInfo selInfo, int annotationId, string initialContent)
=> new PDFAnnotationHighlight
{
StartPage = selInfo.StartPage,
StartIndex = selInfo.StartIndex,
EndPage = selInfo.EndPage,
EndIndex = selInfo.EndIndex,
HtmlContent = "<div>"+initialContent+"</div>",
AnnotationId = annotationId
};

public int GetSortingKey() => StartPage * 10000 + StartIndex;

#endregion
}
}
11 changes: 10 additions & 1 deletion src/SuperMemoAssistant.Plugins.PDF/Models/PDFCfg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,23 @@ public class PDFCfg : CfgBase<PDFCfg>, INotifyPropertyChangedEx
[Value(Must.MatchPattern, HexREPattern)]
[JsonConverter(typeof(ColorToStringJsonConverter))]
public Color IgnoreHighlightColor { get; set; } = SMConst.Stylesheet.IgnoreColor;
public Color FocusedAnnotationHighlightColor { get; set; } = Color.FromArgb(150,
0,
255,
0);
public Color AnnotationHighlightColor { get; set; } = Color.FromArgb(90,
100,
255,
100);

public double WindowTop { get; set; } = 100;
public double WindowHeight { get; set; } = 600;
public double WindowLeft { get; set; } = 100;
public double WindowWidth { get; set; } = 800;
public WindowState WindowState { get; set; } = WindowState.Normal;

public double SidePanelWidth { get; set; } = 256;
public double SidePanelBookmarksWidth { get; set; } = 256;
public double SidePanelAnnotationsWidth { get; set; } = 256;

// Dictionary

Expand Down
56 changes: 43 additions & 13 deletions src/SuperMemoAssistant.Plugins.PDF/PDF/PDFElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
namespace SuperMemoAssistant.Plugins.PDF.PDF
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
Expand Down Expand Up @@ -60,24 +61,29 @@ public class PDFElement : INotifyPropertyChanged
{
#region Constructors

public delegate void AnnotationAdded(object sender, AnnotationAddedEventArgs e);
public event AnnotationAdded OnAnnotationAdded;

public PDFElement()
{
BinaryMemberId = -1;
StartPage = -1;
EndPage = -1;
StartIndex = -1;
EndIndex = -1;
ReadPage = 0;
ReadPoint = default;
PDFExtracts = new ObservableCollection<PDFTextExtract>();
SMExtracts = new ObservableCollection<PDFTextExtract>();
SMImgExtracts = new ObservableCollection<PDFImageExtract>();
BinaryMemberId = -1;
StartPage = -1;
EndPage = -1;
StartIndex = -1;
EndIndex = -1;
ReadPage = 0;
ReadPoint = default;
PDFExtracts = new ObservableCollection<PDFTextExtract>();
SMExtracts = new ObservableCollection<PDFTextExtract>();
SMImgExtracts = new ObservableCollection<PDFImageExtract>();
IgnoreHighlights = new ObservableCollection<PDFTextExtract>();
AnnotationHighlights = new Dictionary<int, List<PDFAnnotationHighlight>>();

PDFExtracts.CollectionChanged += OnCollectionChanged;
SMExtracts.CollectionChanged += OnCollectionChanged;
SMImgExtracts.CollectionChanged += OnCollectionChanged;
PDFExtracts.CollectionChanged += OnCollectionChanged;
SMExtracts.CollectionChanged += OnCollectionChanged;
SMImgExtracts.CollectionChanged += OnCollectionChanged;
IgnoreHighlights.CollectionChanged += OnCollectionChanged;
OnAnnotationAdded += OnAnnotationAddedEffect;
}

#endregion
Expand Down Expand Up @@ -107,6 +113,8 @@ public PDFElement()
public ObservableCollection<PDFImageExtract> SMImgExtracts { get; }
[JsonProperty(PropertyName = "IH")]
public ObservableCollection<PDFTextExtract> IgnoreHighlights { get; }
[JsonProperty(PropertyName = "AH")]
public Dictionary<int, List<PDFAnnotationHighlight>> AnnotationHighlights { get; }

[JsonProperty(PropertyName = "RPg")]
public int ReadPage { get; set; }
Expand Down Expand Up @@ -501,6 +509,7 @@ private string GetJsonB64()
string elementJson = JsonConvert.SerializeObject(this,
Formatting.None);

//MessageBox.Show("GetJsonB64: " + elementJson.Replace("HTML", "\nHTML")); // TODO NOCHECKIN
return elementJson.ToBase64();
}

Expand Down Expand Up @@ -581,6 +590,27 @@ private void OnCollectionChanged(object sender,
IsChanged = true;
}

[SuppressPropertyChangedWarnings]
private void OnAnnotationAddedEffect(object sender,
AnnotationAddedEventArgs e)
{
IsChanged = true;
}

public void AddAnnotationHighlight(PDFAnnotationHighlight annotationHighlight)
{
OnAnnotationAdded(this, new AnnotationAddedEventArgs() {
NewItem = annotationHighlight
});

int page = annotationHighlight.StartPage;
if (!AnnotationHighlights.ContainsKey(page))
{
AnnotationHighlights[page] = new List<PDFAnnotationHighlight>();
}
AnnotationHighlights[page].Add(annotationHighlight);
}

#endregion


Expand Down
Loading