Просмотр исходного кода

highlights working for moving to position in pdf from source

Brian Gough 12 лет назад
Родитель
Сommit
f914c75712

+ 3 - 4
services/web/public/coffee/ide/pdfng/directives/pdfHighlights.coffee

@@ -4,12 +4,11 @@ app.factory 'pdfHighlights', [ () ->
 	class pdfHighlights
 	class pdfHighlights
 
 
 		constructor: (options) ->
 		constructor: (options) ->
-			@highlightsLayerDiv = options.highlights
-			@viewport = options.viewport
+			@highlightsLayerDiv = options.highlights[0]
 			@highlightElements = []
 			@highlightElements = []
 
 
-		addHighlight: (left, top, width, height) ->
-			rect = @viewport.convertToViewportRectangle([left, top, left + width, top + height])
+		addHighlight: (viewport, left, top, width, height) ->
+			rect = viewport.convertToViewportRectangle([left, top, left + width, top + height])
 			rect = PDFJS.Util.normalizeRect(rect)
 			rect = PDFJS.Util.normalizeRect(rect)
 			element = document.createElement("div")
 			element = document.createElement("div")
 			element.style.left = Math.floor(rect[0]) + 'px'
 			element.style.left = Math.floor(rect[0]) + 'px'

+ 22 - 21
services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee

@@ -102,27 +102,28 @@ define [
 
 
 				scope.$watch "highlights", (areas) ->
 				scope.$watch "highlights", (areas) ->
 					console.log 'got HIGHLIGHTS in pdfJS', areas
 					console.log 'got HIGHLIGHTS in pdfJS', areas
-					return if !areas?
-					highlights = for area in areas or []
-						{
-							page: area.page
-							highlight:
-								left: area.h
-								top: area.v
-								height: area.height
-								width: area.width
-						}
-
-					if highlights.length > 0
-						first = highlights[0]
-						position = {
-							page: first.page
-							offset:
-								left: first.highlight.left
-								top: first.highlight.top - 80
-						}
-						console.log 'position is', position, 'in highlights'
-						scope.pleaseJumpTo = position
+					
+					# return if !areas?
+					# highlights = for area in areas or []
+					# 	{
+					# 		page: area.page
+					# 		highlight:
+					# 			left: area.h
+					# 			top: area.v
+					# 			height: area.height
+					# 			width: area.width
+					# 	}
+
+					# if highlights.length > 0
+					# 	first = highlights[0]
+					# 	position = {
+					# 		page: first.page
+					# 		offset:
+					# 			left: first.highlight.left
+					# 			top: first.highlight.top - 80
+					# 	}
+					# 	console.log 'position is', position, 'in highlights'
+					# 	scope.pleaseJumpTo = position
 					# pdfListView.clearHighlights()
 					# pdfListView.clearHighlights()
 					# pdfListView.setHighlights(highlights, true)
 					# pdfListView.setHighlights(highlights, true)
 
 

+ 19 - 2
services/web/public/coffee/ide/pdfng/directives/pdfPage.coffee

@@ -1,6 +1,6 @@
-app = angular.module 'pdfPage', []
+app = angular.module 'pdfPage', ['pdfHighlights']
 
 
-app.directive 'pdfPage', ['$timeout', ($timeout) ->
+app.directive 'pdfPage', ['$timeout', 'pdfHighlights', ($timeout, pdfHighlights) ->
 	{
 	{
 		require: '^pdfViewer',
 		require: '^pdfViewer',
 		template: '''
 		template: '''
@@ -78,5 +78,22 @@ app.directive 'pdfPage', ['$timeout', ($timeout) ->
 				else if !newVisible && oldVisible
 				else if !newVisible && oldVisible
 					pausePage()
 					pausePage()
 
 
+			highlightsLayer = new pdfHighlights({
+				highlights: highlightsElement
+			})
+
+			scope.$watch 'highlights', (highlights, oldVal) ->
+				console.log 'got highlight watch in pdfPage', scope.page
+				pageHighlights = (h for h in highlights when h.page == scope.page.pageNum)
+				return unless pageHighlights.length
+				scope.document.getPdfViewport(scope.page.pageNum).then (viewport) ->
+					for hl in pageHighlights
+						console.log 'adding highlight', h, viewport
+						top = viewport.viewBox[3] - hl.v
+						highlightsLayer.addHighlight viewport, hl.h, top, hl.width, hl.height
+				$timeout () ->
+					highlightsLayer.clearHighlights()
+				, 1000
+
 	}
 	}
 ]
 ]

+ 9 - 24
services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee

@@ -325,7 +325,7 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) ->
 				console.log 'areas are', areas
 				console.log 'areas are', areas
 				highlights = for area in areas or []
 				highlights = for area in areas or []
 					{
 					{
-						page: area.page - 1
+						page: area.page 
 						highlight:
 						highlight:
 							left: area.h
 							left: area.h
 							top: area.v
 							top: area.v
@@ -337,31 +337,16 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) ->
 				return if !highlights.length
 				return if !highlights.length
 
 
 				first = highlights[0]
 				first = highlights[0]
-				ctrl.setPdfPosition(scope.pages[first.page], {
-						page: scope.pages[first.page]
+
+				scope.document.getPdfViewport(first.page).then (viewport) ->
+					position = {
+						page: first.page
 						offset:
 						offset:
 							left: first.highlight.left
 							left: first.highlight.left
-							top: first.highlight.top - 80
-					})
-
-				for h in highlights
-					console.log 'iterating highlights', h
-					page = scope.pages[h.page]
-					element = page.element
-					viewport = page.viewport
-					highlightsElement = $(element).find('.highlights-layer')
-					highlightsLayer = new pdfHighlights({
-							highlights: highlightsElement
-							viewport: viewport
-					})
-					k=h.highlight
-					highlightsLayer.addHighlight(k.left,k.top,k.width,k.height)
-					#pdfListView.clearHighlights()
-					#ctrl.setHighlights(highlights, true)
-
-					#setTimeout () =>
-					#	pdfListView.clearHighlights()
-					#, 1000
+							top: viewport.viewBox[3] - first.highlight.top + first.highlight.height + 72
+					}
+					ctrl.setPdfPosition(scope.pages[first.page - 1], position)
+
 
 
 	}
 	}
 ]
 ]