Jürgen Spitzmüller wrote:
> maybe someone else has?
>
> The following needs to be done:
>
>
> def convert_graphics_rotation(document):
>
> if we have a graphics inset that has the rotateAngle param and either the
> width, height or scaled param, then add the param scaleBeforeRotation. Else
> do nothing.
>
>
> def revert_graphics_rotation(document):
>
> 1. for every graphics inset that has _no_ scaleBeforeRotation param:
> look if there's a rotateAngle param and either the width, height or scaled
> param. If so, delete rotateAngle and add
>
> special angle=<angle value>,<other special values>
>
> 2. for every other: just delete the scaleBeforeRotation param.
>
>
> I guess this is easy, if you happen to know python.
OK here's a start.
convert_graphics_rotation seems to work (but I'm not sure it really does),
however, revert_graphics_rotation does not.
I really don't know what I'm doing here, so please help.
Jürgen
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py (Revision 18639)
+++ lib/lyx2lyx/LyX.py (Arbeitskopie)
@@ -77,7 +77,7 @@
("1_2", [220], generate_minor_versions("1.2" , 4)),
("1_3", [221], generate_minor_versions("1.3" , 7)),
("1_4", range(222,246), generate_minor_versions("1.4" , 4)),
- ("1_5", range(246,272), generate_minor_versions("1.5" , 0))]
+ ("1_5", range(246,273), generate_minor_versions("1.5" , 0))]
def formats_list():
Index: lib/lyx2lyx/lyx_1_5.py
===================================================================
--- lib/lyx2lyx/lyx_1_5.py (Revision 18639)
+++ lib/lyx2lyx/lyx_1_5.py (Arbeitskopie)
@@ -1311,6 +1311,64 @@
document.textclass = "cv"
+#
+# add scaleBeforeRotation graphics param
+def convert_graphics_rotation(document):
+ " add scaleBeforeRotation graphics parameter. "
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\begin_inset Graphics", i)
+ if i == -1:
+ return
+ j = find_end_of_inset(document.body, i+1)
+ if j == -1:
+ # should not happen
+ document.warning("Malformed LyX document: Could not find end of graphics inset.")
+ # Seach for rotateAngle and width or height or scale
+ # If these params are not there, nothing needs to be done.
+ for k in range(i+1, j-1):
+ if (document.body[k].find("width") or \
+ document.body[k].find("height") or \
+ document.body[k].find("scale") and \
+ document.body[k].find("rotateAngle")):
+ document.body.insert(j-1, 'scaleBeforeRotation')
+ i = i + 1
+
+
+def revert_graphics_rotation(document):
+ " remove scaleBeforeRotation graphics parameter. "
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\begin_inset Graphics", i)
+ if i == -1:
+ return
+ j = find_end_of_inset(document.body, i + 1)
+ if j == -1:
+ # should not happen
+ document.warning("Malformed LyX document: Could not find end of graphics inset.")
+ for k in range(i+1, j-1):
+ # If there's a scaleBeforeRotation param, just remove that
+ if document.body[k].find("scaleBeforeRotation"):
+ document.warning("scaleFound")
+ del document.body[k]
+ return
+ # if not, and if we have rotateAngle and width or height or scale,
+ # we have to put the rotateAngle value to special
+ rotateAngle = get_value(document.body, 'rotateAngle', i+1, j-1)
+ special = get_value(document.body, 'special', i+1, j-1)
+ if (document.body[k].find("width") or \
+ document.body[k].find("height") or \
+ document.body[k].find("scale") and \
+ document.body[k].find("rotateAngle")):
+ if special == "":
+ document.body.insert(j-1, 'special angle=%s' % rotateAngle)
+ else:
+ document.body[k].find("special")
+ document.body.replace[k]('special angle=%s,%s' % (rotateAngle, special))
+ i = i + 1
+
+
+
def convert_tableborder(document):
# The problematic is: LyX double the table cell border as it ignores the "|" character in
# the cell arguments. A fix takes care of this and therefore the "|" has to be removed
@@ -1687,10 +1745,12 @@
[268, []],
[269, []],
[270, []],
- [271, [convert_ext_font_sizes]]
+ [271, [convert_ext_font_sizes]],
+ [272, [convert_graphics_rotation]]
]
revert = [
+ [271, []],
[270, [revert_ext_font_sizes]],
[269, [revert_beamer_alert, revert_beamer_structure]],
[268, [revert_preamble_listings_params, revert_listings_inset, revert_include_listings]],