2014-11-25 11:00:21 -05:00
|
|
|
app = angular.module 'pdfHighlights', []
|
|
|
|
|
|
|
|
app.factory 'pdfHighlights', [ () ->
|
|
|
|
class pdfHighlights
|
|
|
|
|
|
|
|
constructor: (options) ->
|
2014-11-28 06:57:23 -05:00
|
|
|
@highlightsLayerDiv = options.highlights[0]
|
2014-11-25 11:00:21 -05:00
|
|
|
@highlightElements = []
|
|
|
|
|
2014-11-28 06:57:23 -05:00
|
|
|
addHighlight: (viewport, left, top, width, height) ->
|
|
|
|
rect = viewport.convertToViewportRectangle([left, top, left + width, top + height])
|
2014-11-25 11:00:21 -05:00
|
|
|
rect = PDFJS.Util.normalizeRect(rect)
|
|
|
|
element = document.createElement("div")
|
|
|
|
element.style.left = Math.floor(rect[0]) + 'px'
|
|
|
|
element.style.top = Math.floor(rect[1]) + 'px'
|
|
|
|
element.style.width = Math.ceil(rect[2] - rect[0]) + 'px'
|
|
|
|
element.style.height = Math.ceil(rect[3] - rect[1]) + 'px'
|
|
|
|
@highlightElements.push(element)
|
|
|
|
@highlightsLayerDiv.appendChild(element)
|
|
|
|
element
|
|
|
|
|
|
|
|
clearHighlights: () ->
|
|
|
|
for h in @highlightElements
|
|
|
|
h.remove()
|
|
|
|
@highlightElements = []
|
|
|
|
]
|