Transform old implementation to new implementation of border styles
This commit is contained in:
parent
9ba4f74370
commit
9550c00184
@ -102,45 +102,8 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some types of annotations have border style dict which has more
|
this.borderStyle = data.borderStyle = new AnnotationBorderStyle();
|
||||||
// info than the border array
|
this.setBorderStyle(dict);
|
||||||
if (dict.has('BS')) {
|
|
||||||
var borderStyle = dict.get('BS');
|
|
||||||
data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
|
|
||||||
} else {
|
|
||||||
var borderArray = dict.get('Border') || [0, 0, 1];
|
|
||||||
data.borderWidth = borderArray[2] || 0;
|
|
||||||
|
|
||||||
// TODO: implement proper support for annotations with line dash patterns.
|
|
||||||
var dashArray = borderArray[3];
|
|
||||||
if (data.borderWidth > 0 && dashArray) {
|
|
||||||
if (!isArray(dashArray)) {
|
|
||||||
// Ignore the border if dashArray is not actually an array,
|
|
||||||
// this is consistent with the behaviour in Adobe Reader.
|
|
||||||
data.borderWidth = 0;
|
|
||||||
} else {
|
|
||||||
var dashArrayLength = dashArray.length;
|
|
||||||
if (dashArrayLength > 0) {
|
|
||||||
// According to the PDF specification: the elements in a dashArray
|
|
||||||
// shall be numbers that are nonnegative and not all equal to zero.
|
|
||||||
var isInvalid = false;
|
|
||||||
var numPositive = 0;
|
|
||||||
for (var i = 0; i < dashArrayLength; i++) {
|
|
||||||
var validNumber = (+dashArray[i] >= 0);
|
|
||||||
if (!validNumber) {
|
|
||||||
isInvalid = true;
|
|
||||||
break;
|
|
||||||
} else if (dashArray[i] > 0) {
|
|
||||||
numPositive++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isInvalid || numPositive === 0) {
|
|
||||||
data.borderWidth = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.appearance = getDefaultAppearance(dict);
|
this.appearance = getDefaultAppearance(dict);
|
||||||
data.hasAppearance = !!this.appearance;
|
data.hasAppearance = !!this.appearance;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals PDFJS, Util, AnnotationType */
|
/* globals PDFJS, Util, AnnotationType, AnnotationBorderStyleType, warn,
|
||||||
|
CustomStyle */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -50,19 +51,64 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
|
|||||||
var width = item.rect[2] - item.rect[0];
|
var width = item.rect[2] - item.rect[0];
|
||||||
var height = item.rect[3] - item.rect[1];
|
var height = item.rect[3] - item.rect[1];
|
||||||
|
|
||||||
var bWidth = item.borderWidth || 0;
|
// Border
|
||||||
if (bWidth) {
|
if (item.borderStyle.width > 0) {
|
||||||
width = width - 2 * bWidth;
|
// Border width
|
||||||
height = height - 2 * bWidth;
|
container.style.borderWidth = item.borderStyle.width + 'px';
|
||||||
cstyle.borderWidth = bWidth + 'px';
|
if (item.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
|
||||||
var color = item.color;
|
// Underline styles only have a bottom border, so we do not need
|
||||||
if (drawBorder && color) {
|
// to adjust for all borders. This yields a similar result as
|
||||||
cstyle.borderStyle = 'solid';
|
// Adobe Acrobat/Reader.
|
||||||
cstyle.borderColor = Util.makeCssRgb(Math.round(color[0] * 255),
|
width = width - 2 * item.borderStyle.width;
|
||||||
Math.round(color[1] * 255),
|
height = height - 2 * item.borderStyle.width;
|
||||||
Math.round(color[2] * 255));
|
}
|
||||||
|
|
||||||
|
// Horizontal and vertical border radius
|
||||||
|
var horizontalRadius = item.borderStyle.horizontalCornerRadius;
|
||||||
|
var verticalRadius = item.borderStyle.verticalCornerRadius;
|
||||||
|
if (horizontalRadius > 0 || verticalRadius > 0) {
|
||||||
|
var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
|
||||||
|
CustomStyle.setProp('borderRadius', container, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Border style
|
||||||
|
switch (item.borderStyle.style) {
|
||||||
|
case AnnotationBorderStyleType.SOLID:
|
||||||
|
container.style.borderStyle = 'solid';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AnnotationBorderStyleType.DASHED:
|
||||||
|
container.style.borderStyle = 'dashed';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AnnotationBorderStyleType.BEVELED:
|
||||||
|
warn('Unimplemented border style: beveled');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AnnotationBorderStyleType.INSET:
|
||||||
|
warn('Unimplemented border style: inset');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AnnotationBorderStyleType.UNDERLINE:
|
||||||
|
container.style.borderBottomStyle = 'solid';
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Border color
|
||||||
|
if (item.color) {
|
||||||
|
container.style.borderColor =
|
||||||
|
Util.makeCssRgb(Math.round(item.color[0] * 255),
|
||||||
|
Math.round(item.color[1] * 255),
|
||||||
|
Math.round(item.color[2] * 255));
|
||||||
|
} else {
|
||||||
|
// Default color is black, but that's not obvious from the spec.
|
||||||
|
container.style.borderColor = 'rgb(0,0,0)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cstyle.width = width + 'px';
|
cstyle.width = width + 'px';
|
||||||
cstyle.height = height + 'px';
|
cstyle.height = height + 'px';
|
||||||
return container;
|
return container;
|
||||||
|
Loading…
Reference in New Issue
Block a user