Dear Developers,
the last release of python-docx has been submitted around 2-year ago. Is there any future or schedule for a version 0.8.7?
Thank you very much,
Yes.
@scanny can you explain more?
Perhaps we could try to get an overview of what features are planned for the next release, and more importantly who is going to do what :)
If there is a backlog/to do list, people might be more willing to contribute.
We could also try to split some of the bigger projects into smaller, easier to implement parts. For instance, implement only the oxml part of a bigger feature, which can be committed to its feature branch, giving other people the chance to continue working on it.
If I would have to make a list right now, it would something like this:
May I add:
wmf/emf is interesting because it is vectorial image, it is supported by the docx format and it can be generated as instance from an svg image by inkscape, typically:
inkscape -t -f image.svg -M image.emf
Note that implementation is quite easy in python-docx, except that actually, i did not see any clean work around except patching the module.
Below my patch:
diff -ruN python-docx-master/docx/image/constants.py python-docx-emf/docx/image/constants.py
--- python-docx-master/docx/image/constants.py 2016-06-23 07:02:30.000000000 +0800
+++ python-docx-emf/docx/image/constants.py 2018-03-29 13:07:27.870696556 +0800
@@ -102,6 +102,7 @@
JPEG = 'image/jpeg'
PNG = 'image/png'
TIFF = 'image/tiff'
+ EMF = 'image/emf'
class PNG_CHUNK_TYPE(object):
diff -ruN python-docx-master/docx/image/emf.py python-docx-emf/docx/image/emf.py
--- python-docx-master/docx/image/emf.py 1970-01-01 08:00:00.000000000 +0800
+++ python-docx-emf/docx/image/emf.py 2018-03-29 13:08:05.482783490 +0800
@@ -0,0 +1,71 @@
+# encoding: utf-8
+
+from __future__ import absolute_import, division, print_function
+
+from .constants import MIME_TYPE
+from .exceptions import InvalidImageStreamError
+from .helpers import BIG_ENDIAN, StreamReader
+from .image import BaseImageHeader
+import struct
+
+class Emf(BaseImageHeader):
+ """
+ Image header parser for PNG images
+ """
+ @property
+ def content_type(self):
+ """
+ MIME content type for this image, unconditionally `image/png` for
+ PNG images.
+ """
+ return MIME_TYPE.EMF
+
+ @property
+ def default_ext(self):
+ """
+ Default filename extension, always 'png' for PNG images.
+ """
+ return 'emf'
+
+ @classmethod
+ def from_stream(cls, stream,filename=None):
+ """
+ Return a |Emf| instance having header properties parsed from image in
+ *stream*.
+ """
+
+ """
+ @0 DWORD iType; // fixed
+ @4 DWORD nSize; // var
+ @8 RECTL rclBounds;
+ @24 RECTL rclFrame; // .01 millimeter units L T R B
+ @40 DWORD dSignature; // ENHMETA_SIGNATURE = 0x464D4520
+ DWORD nVersion;
+ DWORD nBytes;
+ DWORD nRecords;
+ WORD nHandles;
+ WORD sReserved;
+ DWORD nDescription;
+ DWORD offDescription;
+ DWORD nPalEntries;
+ SIZEL szlDevice;
+ SIZEL szlMillimeters;
+ """
+ stream.seek(0)
+ x = stream.read(40)
+ stream.seek(0)
+ iType,nSize = struct.unpack("ii",x[0:8])
+ rclBounds = struct.unpack("iiii",x[8:24])
+ rclFrame = struct.unpack("iiii",x[24:40])
+
+ dpi = 300
+ horz_dpi = dpi
+ vert_dpi = dpi
+ mmwidth = (rclFrame[2]-rclFrame[0])/100.0
+ mmheight = (rclFrame[3]-rclFrame[1])/100.0
+ px_width = int(mmwidth*dpi*0.03937008)
+ px_height = int(mmheight*dpi*0.03937008)
+
+ #1 dot/inch = 0.03937008 pixel/millimeter
+ return cls(px_width,px_height,horz_dpi,vert_dpi)
+
diff -ruN python-docx-master/docx/image/image.py python-docx-emf/docx/image/image.py
--- python-docx-master/docx/image/image.py 2016-06-23 07:02:30.000000000 +0800
+++ python-docx-emf/docx/image/image.py 2018-03-29 13:08:56.046900456 +0800
@@ -188,7 +188,7 @@
def read_32(stream):
stream.seek(0)
- return stream.read(32)
+ return stream.read(64)
header = read_32(stream)
for cls, offset, signature_bytes in SIGNATURES:
diff -ruN python-docx-master/docx/image/__init__.py python-docx-emf/docx/image/__init__.py
--- python-docx-master/docx/image/__init__.py 2016-06-23 07:02:30.000000000 +0800
+++ python-docx-emf/docx/image/__init__.py 2018-03-29 13:17:37.296110634 +0800
@@ -14,6 +14,7 @@
from docx.image.jpeg import Exif, Jfif
from docx.image.png import Png
from docx.image.tiff import Tiff
+from docx.image.emf import Emf
SIGNATURES = (
@@ -26,4 +27,5 @@
(Tiff, 0, b'MM\x00*'), # big-endian (Motorola) TIFF
(Tiff, 0, b'II*\x00'), # little-endian (Intel) TIFF
(Bmp, 0, b'BM'),
+ (Emf, 41, b'EMF'),
)
@raphaelvalentin I would say, create a PR, a feature analysis (is this code all we need, or is there something else required. for instance, I do see a difference between the *.PNG image implementation and the *.BMP implementation) and commit this code together with the required functional and unit tests!
I'm sorry that I'm still a rookie, so I can't play a big role, but I like this way of cooperation. I need to improve myself first. I hope to participate in the project one day
v0.8.7 was released a few weeks ago.
Most helpful comment
Yes.