205
205
class FloatObject(decimal.Decimal, PdfObject):
206
def __new__(cls, value="0", context=None):
207
return decimal.Decimal.__new__(cls, str(value), context)
206
210
def writeToStream(self, stream, encryption_key):
207
211
stream.write(str(self).encode("ascii"))
459
463
def __getitem__(self, key):
460
464
return dict.__getitem__(self, key).getObject()
467
# Retrieves XMP (Extensible Metadata Platform) data relevant to the
468
# this object, if available.
470
# Stability: Added in v1.12, will exist for all future v1.x releases.
471
# @return Returns a {@link #xmp.XmpInformation XmlInformation} instance
472
# that can be used to access XMP metadata from the document. Can also
473
# return None if no metadata was found on the document root.
474
def getXmpMetadata(self):
475
metadata = self.get("/Metadata", None)
478
metadata = metadata.getObject()
480
if not isinstance(metadata, xmp.XmpInformation):
481
metadata = xmp.XmpInformation(metadata)
482
self[NameObject("/Metadata")] = metadata
486
# Read-only property that accesses the {@link
487
# #DictionaryObject.getXmpData getXmpData} function.
489
# Stability: Added in v1.12, will exist for all future v1.x releases.
490
xmpMetadata = property(lambda self: self.getXmpMetadata(), None, None)
462
492
def writeToStream(self, stream, encryption_key):
463
493
stream.write(b"<<\n")
464
494
for key, value in list(self.items()):
600
630
return self.decodedSelf.getData()
602
632
# create decoded object
603
decoded = StreamObject()
633
decoded = DecodedStreamObject()
604
634
decoded._data = decodeStreamData(self)
605
635
for key, value in list(self.items()):
606
636
if not key in ("/Length", "/Filter", "/DecodeParms"):
620
650
ArrayObject.__init__(self, [self.ensureIsNumber(x) for x in arr])
622
652
def ensureIsNumber(self, value):
623
if not isinstance(value, NumberObject):
624
value = NumberObject(value)
653
if not isinstance(value, (NumberObject, FloatObject)):
654
value = FloatObject(value)
627
657
def __repr__(self):