Пример #1
0
        private void UIThreadSynch_SynchContent(SynchContentEventArgs e)
        {
            if (e.Type == SynchContentEventType.RequestCopyCurrentPage)
              {
            //Sends the highlights, scribbles and notes in the current page
            SendAll(ActualPage);
              }
              else if (e.Type == SynchContentEventType.RequestCopyAll)
              {
            for (int pageIndex = 0; pageIndex < ActualDocument.Pages.Length; pageIndex++)
              SendAll(pageIndex);
              }
              else if (e.Type == SynchContentEventType.Highlight)
              {
            if (e.DocumentID != ActualDocument.ID)
              return;
            if (e.PageIndex < 0 || e.PageIndex >= ActualDocument.Pages.Length)
              return;

            Highlight highlight = e.Content as Highlight;
            var exists = ActualDocument[e.PageIndex].Highlights.FirstOrDefault(tmp => tmp.ID == highlight.ID);
            if (exists != null)
              return;

            ActualDocument[e.PageIndex].Highlights.Add(highlight);
            if (e.PageIndex == ActualPage)
              AddHighlight(highlight.Line, cHighlights);
            PushToUndoStack(ActiveReadingTool.Highlighter, highlight);
              }
              else if (e.Type == SynchContentEventType.Stroke)
              {
            if (e.DocumentID != ActualDocument.ID)
              return;
            if (e.PageIndex < 0 || e.PageIndex >= ActualDocument.Pages.Length)
              return;

            Stroke stroke = e.Content as Stroke;
            Guid collectionID = new Guid((String)stroke.GetPropertyData(strokeCollectionPropertyID));
            ScribbleCollection collection = (ScribbleCollection)ActualDocument[e.PageIndex].ScribblingCollections.FirstOrDefault(tmp => tmp.ID == collectionID);
            if (collection == null)
            {
              collection = new ScribbleCollection() { ID = collectionID, Scribbles = new StrokeCollection() };
              ActualDocument[e.PageIndex].ScribblingCollections.Add(collection);
            }

            Guid strokeID = Guid.Parse(stroke.GetPropertyData(strokeObjectPropertyID) as String);
            var strokeExist = collection.Scribbles.FirstOrDefault(tmp => Guid.Parse(tmp.GetPropertyData(strokeObjectPropertyID) as String) == strokeID);
            if (strokeExist != null)
              return;

            collection.Scribbles.Add(stroke);
            if (e.PageIndex == ActualPage)
              inkCScribble.Strokes.Add(stroke);
            PushToUndoStack(ActiveReadingTool.Pen, collection, stroke);
              }
              else if (e.Type == SynchContentEventType.Note)
              {
            if (e.DocumentID != ActualDocument.ID)
              return;
            if (e.PageIndex < 0 || e.PageIndex >= ActualDocument.Pages.Length)
              return;

            Note note = e.Content as Note;
            var exists = ActualDocument[e.PageIndex].Annotations.FirstOrDefault(tmp => tmp.ID == note.ID);
            if (exists != null)
              return;

            if (e.PageIndex == ActualPage)
              AddNote(note);
            ActualDocument[e.PageIndex].Annotations.Add(note);
              }
        }
Пример #2
0
        private void inkCScribble_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (inkCScribble.Strokes.Count > 0)
              {
            currentStroke = inkCScribble.Strokes[inkCScribble.Strokes.Count - 1];
            currentStroke.AddPropertyData(strokeObjectPropertyID, Guid.NewGuid().ToString());
              }

              if (CurrentTool == ActiveReadingTool.Pen) //add strokes to Document (when strokes are close to each other cluster them in one strokeCollection)
              {
            foreach (ScribbleCollection collection in ActualDocument[ActualPage].ScribblingCollections)
            {
              if (Distance(currentStroke.GetBounds().TopLeft, new System.Windows.Point(collection.X, collection.Y)) < defaultClusterStrokeDistanceCm ||
            Distance(currentStroke.GetBounds().BottomRight, new System.Windows.Point(collection.X, collection.Y)) < defaultClusterStrokeDistanceCm)
              {
            if (!collection.Scribbles.Contains(currentStroke))
            {
              collection.Scribbles.Add(currentStroke);
              currentStroke.AddPropertyData(strokeCollectionPropertyID, collection.ID.ToString());

              //creates a point for undo for this action
              PushToUndoStack(ActiveReadingTool.Pen, collection, currentStroke);
            }
            return;
              }
            }

            //if stroke is not close to another one, create new collection
            ScribbleCollection newCollection = new ScribbleCollection();
            newCollection.Scribbles = new StrokeCollection();
            newCollection.Scribbles.Add(currentStroke);
            currentStroke.AddPropertyData(strokeCollectionPropertyID, newCollection.ID.ToString());
            ActualDocument[ActualPage].ScribblingCollections.Add(newCollection);

            //creates a point for undo for this action
            PushToUndoStack(ActiveReadingTool.Pen, newCollection);
              }
              else if (CurrentTool == ActiveReadingTool.Eraser)
            inkCScribble.Strokes.Remove(currentStroke); //remove red eraser stroke
        }
Пример #3
0
 public IActiveReaderMarker Clone()
 {
     ScribbleCollection clone = new ScribbleCollection();
       clone.ScribblingXAML = ScribblingXAML;
       return clone;
 }