Kaydet (Commit) c1bfac2c authored tarafından László Németh's avatar László Németh

librelogo UI fixes, gradients, log10, improved random colors

Change-Id: I7ef59f9ce589ab0d68b02c1b2ba61c061f9c51ae
üst 8c52b5dd
2014-03-18 László Németh:
* Start icon inserts and starts a simple localized demo program in an empty
document (UI fix for the missing feedback)
* LOG10 function
* PENTRANSPARENCY, FILLTRANSPARENCY: set transparency of the actual color:
- PENTRANSPARENCY 50 ; 50% transparency of the lines
- FILLTRANSPARENCY 20 ; 20% transparency of the areas
* fill gradient support
- FILLCOLOR ['red', 'blue'] ; gradient between red and blue
- FILLCOLOR [[255, 255, 255], [255, 128, 0]] ; between white and orange
- FILLCOLOR ['red', 'blue', 0, 90, 20] ; linear, 90deg gradient with 20% border
- FILLCOLOR ['red', 'blue', 0, 90, 20, 0, 0, 200, 50] ; from 200% to 50% intensity
- FILLCOLOR ['red', 'blue', 2, 0, 0, 50, 50] ; radial, with 50-50% x, y (centre)
* transparency gradient support (similar settings, without intensity values)
- FILLTRANSPARENCY [75] ; linear gradient from 75% to 0% transparency
- FILLTRANSPARENCY [75, 25] ; linear gradient from 75% to 25% transparency
- FILLTRANSPARENCY [75, 25, 2, 0, 20, 50, 50] ; radial with 20% border, 50-50% x, y
* normalized random colors for the visible spectrum (check FILLCOLOR ANY)
* magic icon sets also page zoom + page break for 2-page program editing
* fix multiple document handling using OfficeDocument.RuntimeUID
instead of Document.Title:
- "Saving as" doesn't create a new turtle
- use current doc. instead of old ones (eg. new Untitled 1 instead of the renamed one)
* change icon order: magic icon before input bar for better undocked Logo
toolbar (two-line, instead of three-line), suggested by Gilvan Vilarim
* keep turtle selection instead of the bad text selection at the end of the run
* support capitalized color names in the translations (fix Slovak translation)
2014-02-04 László Németh:
* avoid to translate comments: http://bug.openscope.org/browse/OOO-837,
reported by Levente Kovács
2014-01-07 László Németh:
* fix messagebox (API changes)
2014-01-01 László Németh:
* path, interop. and color name fixes
2013-10-28: László Németh
* fix parsing problem of functions
2013-10-25:
* fix Logo program halt at font settings (Windows)
* fix division with measurements
2013-10-24 László Németh: 2013-10-24 László Németh:
* synchronize Writer/Draw when saving cropped SVG to avoid program halt, * synchronize Writer/Draw when saving cropped SVG to avoid program halt,
huge sleeps (the workaround) have been removed huge sleeps (the workaround) have been removed
......
...@@ -48,6 +48,10 @@ __COLORS__ = ['BLACK', 0x000000], ['SILVER', 0xc0c0c0], ['GRAY', 0x808080], \ ...@@ -48,6 +48,10 @@ __COLORS__ = ['BLACK', 0x000000], ['SILVER', 0xc0c0c0], ['GRAY', 0x808080], \
['ORANGE', 0xffa500], ['GOLD', 0xffd700], ['VIOLET', 0x9400d3], \ ['ORANGE', 0xffa500], ['GOLD', 0xffd700], ['VIOLET', 0x9400d3], \
['SKYBLUE', 0x87ceeb], ['CHOCOLATE', 0xd2691e], ['BROWN', 0xa52a2a], \ ['SKYBLUE', 0x87ceeb], ['CHOCOLATE', 0xd2691e], ['BROWN', 0xa52a2a], \
['INVISIBLE', 0xffffffff] ['INVISIBLE', 0xffffffff]
__NORMCOLORS__ = [[[255, 255, 0], 0, -11, 1, -11],
[[255, 128, 0], 1, 116, 1, -33], [[255, 0, 0], 1, 95, 2, 42],
[[255, 0, 255], 2, -213, 0, -106], [[0, 0, 255], 0, 148, 1, 127],
[[0, 255, 255], 1, -128, 2, -63], [[0, 255, 0], 2, 192, 0, 244]]
__STRCONST__ = [i[0] for i in __COLORS__] + ['NONE', 'BEVEL', 'MITER', 'ROUNDED', 'SOLID', 'DASH', 'DOTTED', 'BOLD', 'ITALIC', 'UPRIGHT', 'NORMAL', "HOUR", "PT", "INCH", "MM", "CM"] __STRCONST__ = [i[0] for i in __COLORS__] + ['NONE', 'BEVEL', 'MITER', 'ROUNDED', 'SOLID', 'DASH', 'DOTTED', 'BOLD', 'ITALIC', 'UPRIGHT', 'NORMAL', "HOUR", "PT", "INCH", "MM", "CM"]
__SLEEP_SLICE_IN_MILLISECONDS__ = 500 __SLEEP_SLICE_IN_MILLISECONDS__ = 500
__PT_TO_TWIP__ = 20 __PT_TO_TWIP__ = 20
...@@ -91,6 +95,7 @@ class __Doc__: ...@@ -91,6 +95,7 @@ class __Doc__:
self.oldlj = __ROUNDED__ self.oldlj = __ROUNDED__
self.continuous = True self.continuous = True
self.areacolor = __FILLCOLOR__ self.areacolor = __FILLCOLOR__
self.t10y = int((__FILLCOLOR__ >> 24) / (255.0/100))
self.hatch = None self.hatch = None
self.textcolor = 0 self.textcolor = 0
self.fontfamily = __BASEFONTFAMILY__ self.fontfamily = __BASEFONTFAMILY__
...@@ -98,9 +103,11 @@ class __Doc__: ...@@ -98,9 +103,11 @@ class __Doc__:
self.fontweight = 100 self.fontweight = 100
self.fontstyle = 0 self.fontstyle = 0
from math import pi, sin, cos, asin, sqrt from math import pi, sin, cos, asin, sqrt, log10
from com.sun.star.awt import Point as __Point__ from com.sun.star.awt import Point as __Point__
from com.sun.star.awt import Gradient as __Gradient__
from com.sun.star.awt.GradientStyle import LINEAR as __GradientStyle_LINEAR__
from com.sun.star.drawing import LineDash as __LineDash__ from com.sun.star.drawing import LineDash as __LineDash__
from com.sun.star.drawing import Hatch as __Hatch__ from com.sun.star.drawing import Hatch as __Hatch__
from com.sun.star.drawing import PolyPolygonBezierCoords as __Bezier__ from com.sun.star.drawing import PolyPolygonBezierCoords as __Bezier__
...@@ -114,6 +121,7 @@ from com.sun.star.drawing.LineJoint import BEVEL as __BEVEL__ ...@@ -114,6 +121,7 @@ from com.sun.star.drawing.LineJoint import BEVEL as __BEVEL__
from com.sun.star.drawing.LineJoint import MITER as __MITER__ from com.sun.star.drawing.LineJoint import MITER as __MITER__
from com.sun.star.drawing.LineJoint import ROUND as __ROUNDED__ from com.sun.star.drawing.LineJoint import ROUND as __ROUNDED__
from com.sun.star.drawing.FillStyle import NONE as __FillStyle_NONE__ from com.sun.star.drawing.FillStyle import NONE as __FillStyle_NONE__
from com.sun.star.drawing.FillStyle import GRADIENT as __FillStyle_GRADIENT__
from com.sun.star.drawing.LineStyle import NONE as __LineStyle_NONE__ from com.sun.star.drawing.LineStyle import NONE as __LineStyle_NONE__
from com.sun.star.drawing.LineStyle import SOLID as __LineStyle_SOLID__ from com.sun.star.drawing.LineStyle import SOLID as __LineStyle_SOLID__
from com.sun.star.drawing.LineStyle import DASH as __LineStyle_DASHED__ from com.sun.star.drawing.LineStyle import DASH as __LineStyle_DASHED__
...@@ -174,11 +182,10 @@ def __getdocument__(): ...@@ -174,11 +182,10 @@ def __getdocument__():
global __docs__, _ global __docs__, _
doc = XSCRIPTCONTEXT.getDocument() doc = XSCRIPTCONTEXT.getDocument()
try: try:
_ = __docs__[doc.Title] _ = __docs__[doc.RuntimeUID]
_.doc.Title # Is existing instance (not the garbage of the previous instance of a reopened document or a new "Untitled 1")?
except: except:
_ = __Doc__(doc) _ = __Doc__(doc)
__docs__[doc.Title] = _ __docs__[doc.RuntimeUID] = _
# input function, result: input string or 0 # input function, result: input string or 0
def Input(s): def Input(s):
...@@ -306,20 +313,22 @@ def __locname__(name, l = -1): ...@@ -306,20 +313,22 @@ def __locname__(name, l = -1):
return to_unicode(name) return to_unicode(name)
def __getcursor__(fulltext): def __getcursor__(fulltext):
realselection = False
try: try:
text = _.doc.getCurrentController().getViewCursor().getText().createTextCursor() # copy selection (also in frames) text = _.doc.getCurrentController().getViewCursor().getText().createTextCursor() # copy selection (also in frames)
text.gotoRange(_.doc.getCurrentController().getViewCursor(), False) text.gotoRange(_.doc.getCurrentController().getViewCursor(), False)
if fulltext: if fulltext:
1/len(text.getString()) # exception, if zero length 1/len(text.getString()) # exception, if zero length
realselection = True
except: except:
text = _.doc.getText().createTextCursorByRange(_.doc.getText().getStart()) text = _.doc.getText().createTextCursorByRange(_.doc.getText().getStart())
text.gotoEnd(True) text.gotoEnd(True)
return text return text, realselection
def __translate__(arg = None): def __translate__(arg = None):
global _ global _
__getdocument__() __getdocument__()
selection = __getcursor__(True) selection = __getcursor__(True)[0]
__initialize__() __initialize__()
__setlang__() __setlang__()
# detect language # detect language
...@@ -374,11 +383,20 @@ def __translate__(arg = None): ...@@ -374,11 +383,20 @@ def __translate__(arg = None):
for i in __STRCONST__: for i in __STRCONST__:
text = re.sub(quoted % lang[i], __l12n__(_.lng)[i].split("|")[0].upper(), text) text = re.sub(quoted % lang[i], __l12n__(_.lng)[i].split("|")[0].upper(), text)
text = re.sub(__DECODE_COMMENT_REGEX__, __decodecomment__, text) text = re.sub(__DECODE_COMMENT_REGEX__, __decodecomment__, text)
if _.doc.getText().compareRegionStarts(selection.getStart(), _.doc.getText().getStart()) == 0:
pagebreak = True
selection.setString("\n" + text.lstrip("\n"))
else:
pagebreak = False
selection.setString(text) selection.setString(text)
# convert to paragraphs # convert to paragraphs
__dispatcher__(".uno:ExecuteSearch", (__getprop__("SearchItem.SearchString", r"\n"), __getprop__("SearchItem.ReplaceString", r"\n"), \ __dispatcher__(".uno:ExecuteSearch", (__getprop__("SearchItem.SearchString", r"\n"), __getprop__("SearchItem.ReplaceString", r"\n"), \
__getprop__("Quiet", True), __getprop__("SearchItem.Command", 3), __getprop__("SearchItem.StyleFamily", 2), \ __getprop__("Quiet", True), __getprop__("SearchItem.Command", 3), __getprop__("SearchItem.StyleFamily", 2), \
__getprop__("SearchItem.AlgorithmType", 1), __getprop__("SearchItem.RowDirection", 1), __getprop__("SearchItem.SearchFlags", 65536))) __getprop__("SearchItem.AlgorithmType", 1), __getprop__("SearchItem.RowDirection", 1), __getprop__("SearchItem.SearchFlags", 65536)))
# set 2-page layout
if pagebreak:
selection.getStart().BreakType = 4
__dispatcher__(".uno:ZoomPage")
class LogoProgram(threading.Thread): class LogoProgram(threading.Thread):
def __init__(self, code): def __init__(self, code):
...@@ -389,12 +407,12 @@ class LogoProgram(threading.Thread): ...@@ -389,12 +407,12 @@ class LogoProgram(threading.Thread):
global __thread__ global __thread__
try: try:
exec(self.code) exec(self.code)
if _.origcursor: if _.origcursor[0] and _.origcursor[1]:
__dispatcher__(".uno:Escape") __dispatcher__(".uno:Escape")
try: try:
_.doc.CurrentController.getViewCursor().gotoRange(_.origcursor, False) _.doc.CurrentController.getViewCursor().gotoRange(_.origcursor[0], False)
except: except:
_.doc.CurrentController.getViewCursor().gotoRange(_.origcursor.getStart(), False) _.doc.CurrentController.getViewCursor().gotoRange(_.origcursor[0].getStart(), False)
except Exception as e: except Exception as e:
try: try:
TRACEPATTERN = '"<string>", line ' TRACEPATTERN = '"<string>", line '
...@@ -473,7 +491,7 @@ def __initialize__(): ...@@ -473,7 +491,7 @@ def __initialize__():
_.initialize() _.initialize()
turtlehome() turtlehome()
_.doc.CurrentController.select(shape) _.doc.CurrentController.select(shape)
shape.FillColor, transparence = __splitcolor__(_.areacolor) shape.FillColor, transparence = __splitcolor__(_.areacolor, shape)
shape.LineColor, shape.LineTransparence = __splitcolor__(_.pencolor) shape.LineColor, shape.LineTransparence = __splitcolor__(_.pencolor)
elif shape.Visible: elif shape.Visible:
if shape.FillStyle == __FillStyle_NONE__: if shape.FillStyle == __FillStyle_NONE__:
...@@ -490,7 +508,7 @@ def __initialize__(): ...@@ -490,7 +508,7 @@ def __initialize__():
_.pencolor = shape.LineColor + (int(255.0 * shape.LineTransparence/100) << 24) _.pencolor = shape.LineColor + (int(255.0 * shape.LineTransparence/100) << 24)
shape.LineJoint = __ROUNDED__ shape.LineJoint = __ROUNDED__
shape.Shadow = True shape.Shadow = True
shape.FillColor, transparence = __splitcolor__(_.areacolor) shape.FillColor, transparence = __splitcolor__(_.areacolor, shape)
shape.FillTransparence = min(95, transparence) shape.FillTransparence = min(95, transparence)
shape.ShadowColor, shape.ShadowTransparence, shape.ShadowXDistance, shape.ShadowYDistance = (0, 20, 0, 0) shape.ShadowColor, shape.ShadowTransparence, shape.ShadowXDistance, shape.ShadowYDistance = (0, 20, 0, 0)
shape.LineWidth = min(_.pensize, (1 + _.pen * 2) * __PT_TO_TWIP__) / __MM10_TO_TWIP__ shape.LineWidth = min(_.pensize, (1 + _.pen * 2) * __PT_TO_TWIP__) / __MM10_TO_TWIP__
...@@ -634,9 +652,9 @@ def run(arg=None, arg2 = -1): ...@@ -634,9 +652,9 @@ def run(arg=None, arg2 = -1):
__thread__ = 1 __thread__ = 1
try: try:
__getdocument__() __getdocument__()
_.origcursor = None _.origcursor = [None, None]
if arg2 == -1: if arg2 == -1:
_.origcursor, _.cursor = __getcursor__(False), __getcursor__(True) _.origcursor, _.cursor = __getcursor__(False), __getcursor__(True)[0]
__dispatcher__(".uno:Escape") __dispatcher__(".uno:Escape")
c = _.doc.Text.createTextCursor() # go to the first page c = _.doc.Text.createTextCursor() # go to the first page
c.gotoStart(False) c.gotoStart(False)
...@@ -649,6 +667,11 @@ def run(arg=None, arg2 = -1): ...@@ -649,6 +667,11 @@ def run(arg=None, arg2 = -1):
with __lock__: with __lock__:
__thread__ = None __thread__ = None
return None return None
elif len(arg2) == 0 and _.origcursor[1]:
_.origcursor[0].setString("fontcolor 'green'\nlabel 'LIBRE'\npu\nback 30\npic [\n\tfc any\n\tcircle 40\n\tfontcolor 'black'\n\tlabel 'LOGO'\n\tleft 180\n\tfd 20\n\tpd\n\tpc any\n\tps 1\n\tfd 40\n\trepeat 20 [\n\t\tfd repcount*2\n\t\trt 90\n\t]\n]\npu pos any pd")
__translate__()
_.origcursor, _.cursor = __getcursor__(False), __getcursor__(True)[0]
arg2 = _.cursor.getString()
else: else:
__initialize__() __initialize__()
__setlang__() __setlang__()
...@@ -706,6 +729,9 @@ def clearscreen(arg=None): ...@@ -706,6 +729,9 @@ def clearscreen(arg=None):
if not turtle: if not turtle:
__initialize__() __initialize__()
if not __halt__: if not __halt__:
# avoid unintentional image deletion in large documents
if len(__getcursor__(True)[0].getString()) < 5000:
__cs__(False)
return return
__cs__(False) __cs__(False)
__dispatcher__(".uno:Escape") __dispatcher__(".uno:Escape")
...@@ -949,12 +975,12 @@ def __fillit__(filled = True): ...@@ -949,12 +975,12 @@ def __fillit__(filled = True):
shape.LineCap = _.linecap shape.LineCap = _.linecap
shape.LineWidth = _.pensize / __MM10_TO_TWIP__ shape.LineWidth = _.pensize / __MM10_TO_TWIP__
shape.LineColor, shape.LineTransparence = __splitcolor__(_.pencolor) shape.LineColor, shape.LineTransparence = __splitcolor__(_.pencolor)
shape.FillColor, shape.FillTransparence = __splitcolor__(_.areacolor) shape.FillColor, shape.FillTransparence = __splitcolor__(_.areacolor, shape)
if _.hatch: if _.hatch:
shape.FillBackground = True if shape.FillTransparence != 100 else False shape.FillBackground = True if shape.FillTransparence != 100 else False
shape.FillHatch = _.hatch shape.FillHatch = _.hatch
shape.FillStyle = 3 shape.FillStyle = 3
else: elif type(_.areacolor) != tuple:
shape.FillStyle = int(filled) shape.FillStyle = int(filled)
if shape.LineTransparence == 100: if shape.LineTransparence == 100:
shape.LineStyle = 0 shape.LineStyle = 0
...@@ -982,7 +1008,7 @@ def __fillit__(filled = True): ...@@ -982,7 +1008,7 @@ def __fillit__(filled = True):
oldshape.FillStyle = int(filled) oldshape.FillStyle = int(filled)
oldshape.LineWidth = _.pensize / __MM10_TO_TWIP__ oldshape.LineWidth = _.pensize / __MM10_TO_TWIP__
oldshape.LineColor, oldshape.LineTransparence = __splitcolor__(_.pencolor) oldshape.LineColor, oldshape.LineTransparence = __splitcolor__(_.pencolor)
oldshape.FillColor, oldshape.FillTransparence = __splitcolor__(_.areacolor) oldshape.FillColor, oldshape.FillTransparence = __splitcolor__(_.areacolor, oldshape)
def point(): def point():
oldpen, _.pen = _.pen, 1 oldpen, _.pen = _.pen, 1
...@@ -1003,12 +1029,12 @@ def __boxshape__(shapetype, l): ...@@ -1003,12 +1029,12 @@ def __boxshape__(shapetype, l):
shape.LineJoint = _.linejoint shape.LineJoint = _.linejoint
shape.LineCap = _.linecap shape.LineCap = _.linecap
shape.LineColor, shape.LineTransparence = __splitcolor__(_.pencolor) shape.LineColor, shape.LineTransparence = __splitcolor__(_.pencolor)
shape.FillColor, shape.FillTransparence = __splitcolor__(_.areacolor) shape.FillColor, shape.FillTransparence = __splitcolor__(_.areacolor, shape, turtle.RotateAngle)
if _.hatch: if _.hatch:
shape.FillBackground = True if shape.FillTransparence != 100 else False shape.FillBackground = True if shape.FillTransparence != 100 else False
shape.FillHatch = _.hatch shape.FillHatch = _.hatch
shape.FillStyle = 3 shape.FillStyle = 3
else: elif type(_.areacolor) != tuple:
shape.FillStyle = 1 shape.FillStyle = 1
if shape.LineTransparence == 100: if shape.LineTransparence == 100:
shape.LineStyle = 0 shape.LineStyle = 0
...@@ -1163,7 +1189,18 @@ def __color__(c): ...@@ -1163,7 +1189,18 @@ def __color__(c):
return c return c
if type(c) == unicode: if type(c) == unicode:
if c == u'any': if c == u'any':
return int(random.random() * 2**31) # max. 50% transparency rc, rv, rgray = __NORMCOLORS__[int(random.random()*7)], random.random(), random.random() ** 0.5
ratio = 1.0*abs(rc[2])/(abs(rc[2]) + abs(rc[4]))
newcol = list(rc[0])
if rv < ratio:
newcol[rc[1]] += rc[2] * rv/ratio
else:
newcol[rc[3]] += rc[4] * (rv - ratio)/(1 - ratio)
# random grayness
rdark = 1 - 2**4 * (random.random()-0.5)**4
for i in range(0, 3):
newcol[i] = 255 * (rgray + (newcol[i]/255.0 - rgray) * rdark)
return __color__(newcol)
if c[0:1] == '~': if c[0:1] == '~':
c = __componentcolor__(__colors__[_.lng][c[1:].lower()]) c = __componentcolor__(__colors__[_.lng][c[1:].lower()])
for i in range(3): for i in range(3):
...@@ -1171,11 +1208,13 @@ def __color__(c): ...@@ -1171,11 +1208,13 @@ def __color__(c):
return __color__(c) return __color__(c)
return __colors__[_.lng][c.lower()] return __colors__[_.lng][c.lower()]
if type(c) == list: if type(c) == list:
if len(c) == 1: if len(c) == 1: # color index
return __COLORS__[int(c[0])][1] return __COLORS__[int(c[0])][1]
if len(c) == 3: elif len(c) == 3: # RGB
return (int(c[0])%256 << 16) + (int(c[1])%256 << 8) + int(c[2])%256 return (int(c[0])%256 << 16) + (int(c[1])%256 << 8) + int(c[2])%256
return (int(c[3])%256 << 24) + (int(c[0])%256 << 16) + (int(c[1])%256 << 8) + int(c[2])%256 elif len(c) == 2 or len(c) > 4: # gradient
return (__color__(c[0]), __color__(c[1])) + tuple(c[2:])
return (int(c[3])%256 << 24) + (int(c[0])%256 << 16) + (int(c[1])%256 << 8) + int(c[2])%256 # RGB + alpha
def __linestyle__(s): def __linestyle__(s):
if _.pen == 0: if _.pen == 0:
...@@ -1197,7 +1236,24 @@ def fillstyle(s): ...@@ -1197,7 +1236,24 @@ def fillstyle(s):
elif s <= 10: # using hatching styles of Writer elif s <= 10: # using hatching styles of Writer
fillstyle([[1, 0, 5, 0], [1, 0, 5, 45], [1, 0, 5, -45], [1, 0, 5, 90], [2, [127, 0, 0], 5, 45], [2, [127, 0, 0], 5, 0], [2, [0, 0, 127], 5, 45], [2, [0, 0, 127], 5, 0], [3, [0, 0, 127], 5, 0], [1, 0, 25, 45]][s-1]) fillstyle([[1, 0, 5, 0], [1, 0, 5, 45], [1, 0, 5, -45], [1, 0, 5, 90], [2, [127, 0, 0], 5, 45], [2, [127, 0, 0], 5, 0], [2, [0, 0, 127], 5, 45], [2, [0, 0, 127], 5, 0], [3, [0, 0, 127], 5, 0], [1, 0, 25, 45]][s-1])
def __splitcolor__(c): def __splitcolor__(c, shape = None, angle = None):
if shape and (type(c) == tuple or type(_.t10y) == list):
angle = heading() if angle == None else -angle / 100 + 360
if type(c) == tuple:
shape.FillStyle = __FillStyle_GRADIENT__
# gradient color: [color1, color2, style, angle(must be positive for I/O), border, x_percent, y_percent, color1_intensity_percent, color2_intensity_percent]
d, d[0:len(c)], c = [0, 0, __GradientStyle_LINEAR__, 0, 0, 0, 0, 100, 100], c, c[0]
shape.FillGradient = __Gradient__(d[2], d[0], d[1], (-angle + d[3]) * 10 % 3600, d[4], d[5], d[6], d[7], d[8], 0)
if type(_.t10y) == list: # transparency gradient: [begin_percent, end_percent, style, angle, border, x_percent, y_percent]
table = _.doc.createInstance("com.sun.star.drawing.TransparencyGradientTable")
if not table.hasByName(str(_.t10y) + str(angle)):
t, t[0:len(_.t10y)] = [100, __GradientStyle_LINEAR__, 0, 0, 0, 0, 0], _.t10y
table.insertByName(str(_.t10y) + str(angle), __Gradient__(t[2], t[0] * 0xffffff / 100.0, t[1] * 0xffffff / 100.0, (-angle + t[3]) * 10 % 3600, t[4], t[5], t[6], 100, 100, 0))
shape.FillTransparenceGradientName = str(_.t10y) + str(angle)
c = 0 if type(c) == tuple else c & 0xffffff
else:
shape.FillStyle = __FillStyle_GRADIENT__
c = int(_.t10y * 255.0/100) << 24
"""Split color constants to RGB (3-byte) + transparency (%)""" """Split color constants to RGB (3-byte) + transparency (%)"""
return int(c) & 0xffffff, (int(c) >> 24) / (255.0/100) return int(c) & 0xffffff, (int(c) >> 24) / (255.0/100)
...@@ -1267,13 +1323,39 @@ def pencap(n = -1): ...@@ -1267,13 +1323,39 @@ def pencap(n = -1):
def fillcolor(n = -1): def fillcolor(n = -1):
if n != -1: if n != -1:
_.areacolor = __color__(n) _.areacolor = __color__(n)
if type(_.areacolor) != tuple:
_.t10y = (int(_.areacolor) >> 24) / (255.0/100)
else:
_.t10y = 0
turtle = __getshape__(__TURTLE__) turtle = __getshape__(__TURTLE__)
if turtle and __visible__(turtle): if turtle and __visible__(turtle):
turtle.FillColor, transparence = __splitcolor__(_.areacolor) turtle.FillColor, transparence = __splitcolor__(_.areacolor, turtle)
turtle.FillTransparence = min(95, transparence) turtle.FillTransparence = min(95, transparence)
else: else:
return __componentcolor__(_.areacolor) return __componentcolor__(_.areacolor)
def filltransparency(n = -1):
if n != -1:
if n == u'any':
n = 100 * random.random()
if type(n) != list:
if type(_.areacolor) != tuple:
fillcolor((_.areacolor & 0xffffff) + (int(n * (255.0/100)) << 24))
else:
_.t10y = n
else:
_.t10y = n
else:
return _.t10y
def pentransparency(n = -1):
if n != -1:
if n == u'any':
n = 100 * random.random()
pencolor((_.pencolor & 0xffffff) + (int(n * (255.0/100)) << 24))
else:
return _.pencolor >> 24
def fontcolor(n = -1): def fontcolor(n = -1):
if n != -1: if n != -1:
_.textcolor = __color__(n) _.textcolor = __color__(n)
...@@ -1430,7 +1512,7 @@ def __loadlang__(lang, a): ...@@ -1430,7 +1512,7 @@ def __loadlang__(lang, a):
__colors__[lang] = {} __colors__[lang] = {}
for i in __COLORS__: for i in __COLORS__:
for j in a[i[0]].split("|"): for j in a[i[0]].split("|"):
__colors__[lang][j] = i[1] __colors__[lang][j.lower()] = i[1]
for i in a: for i in a:
if not i[0:3] in ["LIB", "ERR", "PT", "INC", "MM", "CM", "HOU", "DEG"] and not i in __STRCONST__: # uppercase native commands if not i[0:3] in ["LIB", "ERR", "PT", "INC", "MM", "CM", "HOU", "DEG"] and not i in __STRCONST__: # uppercase native commands
a[i] = a[i].upper() a[i] = a[i].upper()
...@@ -1485,6 +1567,7 @@ def __loadlang__(lang, a): ...@@ -1485,6 +1567,7 @@ def __loadlang__(lang, a):
[r"(?<!:)\b(?:%s)\b" % a['COS'], "cos"], [r"(?<!:)\b(?:%s)\b" % a['COS'], "cos"],
[r"(?<!:)\b(?:%s)\b" % a['PI'], "pi"], [r"(?<!:)\b(?:%s)\b" % a['PI'], "pi"],
[r"(?<!:)\b(?:%s)\b" % a['SQRT'], "sqrt"], [r"(?<!:)\b(?:%s)\b" % a['SQRT'], "sqrt"],
[r"(?<!:)\b(?:%s)\b" % a['LOG10'], "log10"],
[r"(?<!:)\b(?:%s)\b" % a['MIN'], "min"], [r"(?<!:)\b(?:%s)\b" % a['MIN'], "min"],
[r"(?<!:)\b(?:%s)\b" % a['MAX'], "max"], [r"(?<!:)\b(?:%s)\b" % a['MAX'], "max"],
[r"(?<!:)\b(?:%s)\b" % a['STOP'], "\nreturn None"], [r"(?<!:)\b(?:%s)\b" % a['STOP'], "\nreturn None"],
...@@ -1494,6 +1577,8 @@ def __loadlang__(lang, a): ...@@ -1494,6 +1577,8 @@ def __loadlang__(lang, a):
[r"(?<!:)\b(?:%s)(\s+|$)" % a['PENJOINT'], "\n)penjoint("], [r"(?<!:)\b(?:%s)(\s+|$)" % a['PENJOINT'], "\n)penjoint("],
[r"(?<!:)\b(?:%s)(\s+|$)" % a['PENCAP'], "\n)pencap("], [r"(?<!:)\b(?:%s)(\s+|$)" % a['PENCAP'], "\n)pencap("],
[r"(?<!:)\b(?:%s)(\s+|$)" % a['FILLCOLOR'], "\n)fillcolor("], [r"(?<!:)\b(?:%s)(\s+|$)" % a['FILLCOLOR'], "\n)fillcolor("],
[r"(?<!:)\b(?:%s)(\s+|$)" % a['FILLTRANSPARENCY'], "\n)filltransparency("],
[r"(?<!:)\b(?:%s)(\s+|$)" % a['PENTRANSPARENCY'], "\n)pentransparency("],
[r"(?<!:)\b(?:%s)(\s+|$)" % a['FILLSTYLE'], "\n)fillstyle("], [r"(?<!:)\b(?:%s)(\s+|$)" % a['FILLSTYLE'], "\n)fillstyle("],
[r"(?<!:)\b(?:%s)(\s+|$)" % a['FONTCOLOR'], "\n)fontcolor("], [r"(?<!:)\b(?:%s)(\s+|$)" % a['FONTCOLOR'], "\n)fontcolor("],
[r"(?<!:)\b(?:%s)(\s+|$)" % a['FONTFAMILY'], "\n)fontfamily("], [r"(?<!:)\b(?:%s)(\s+|$)" % a['FONTFAMILY'], "\n)fontfamily("],
...@@ -1540,7 +1625,7 @@ def __loadlang__(lang, a): ...@@ -1540,7 +1625,7 @@ def __loadlang__(lang, a):
[r"\b([0-9]+([,.][0-9]+)?)(%s)(?!\w)" % a['INCH'], lambda r: str(float(r.group(1).replace(",", "."))*72)], [r"\b([0-9]+([,.][0-9]+)?)(%s)(?!\w)" % a['INCH'], lambda r: str(float(r.group(1).replace(",", "."))*72)],
[r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['MM'], lambda r: str(float(r.group(1).replace(",", "."))*__MM_TO_PT__)], [r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['MM'], lambda r: str(float(r.group(1).replace(",", "."))*__MM_TO_PT__)],
[r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['CM'], lambda r: str(float(r.group(1).replace(",", "."))*__MM_TO_PT__*10)], [r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['CM'], lambda r: str(float(r.group(1).replace(",", "."))*__MM_TO_PT__*10)],
[r"\b(__(?:int|float|string)__len|round|abs|sin|cos|sqrt|set|list|tuple|sorted)\b ((?:\w|\d+([,.]\d+)?|0[xX][0-9a-fA-F]+|[-+*/]| )+)\)" , "\\1(\\2))" ], # fix parsing: (1 + sqrt x) -> (1 + sqrt(x)) [r"\b(__(?:int|float|string)__len|round|abs|sin|cos|sqrt|log10|set|list|tuple|sorted)\b ((?:\w|\d+([,.]\d+)?|0[xX][0-9a-fA-F]+|[-+*/]| )+)\)" , "\\1(\\2))" ], # fix parsing: (1 + sqrt x) -> (1 + sqrt(x))
[r"(?<=[-*/=+,]) ?\n\)(\w+)\(", "\\1()"], # read attributes, eg. x = fillcolor [r"(?<=[-*/=+,]) ?\n\)(\w+)\(", "\\1()"], # read attributes, eg. x = fillcolor
[r"(?<=return) ?\n\)(\w+)\(", "\\1()"], # return + user function [r"(?<=return) ?\n\)(\w+)\(", "\\1()"], # return + user function
[r"(?<=(?:Print|label)\() ?\n\)(\w+)\(", "\\1()\n"] # Print/label + user function [r"(?<=(?:Print|label)\() ?\n\)(\w+)\(", "\\1()\n"] # Print/label + user function
...@@ -1613,7 +1698,7 @@ def __compil__(s): ...@@ -1613,7 +1698,7 @@ def __compil__(s):
s = re.sub(r"(?i)\n[ ]*(%s)[ ]+" % __l12n__(_.lng)['TO'], "\n__def__ ", s) s = re.sub(r"(?i)\n[ ]*(%s)[ ]+" % __l12n__(_.lng)['TO'], "\n__def__ ", s)
subnames = re.findall(u"(?iu)(?<=__def__ )\w+", s) subnames = re.findall(u"(?iu)(?<=__def__ )\w+", s)
globs = "" globs = ""
functions = ["range", "__int__", "__float__", "Random", "Input", "__string__", "len", "round", "abs", "sin", "cos", "sqrt", "set", "list", "tuple", "re.sub", "re.search", "re.findall", "sorted", "min", "max"] functions = ["range", "__int__", "__float__", "Random", "Input", "__string__", "len", "round", "abs", "sin", "cos", "sqrt", "log10", "set", "list", "tuple", "re.sub", "re.search", "re.findall", "sorted", "min", "max"]
if len(subnames) > 0: if len(subnames) > 0:
globs = "global %s" % ", ".join(subnames) globs = "global %s" % ", ".join(subnames)
......
...@@ -29,6 +29,8 @@ DOTTED=dotted ...@@ -29,6 +29,8 @@ DOTTED=dotted
CLOSE=close CLOSE=close
FILL=fill FILL=fill
FILLCOLOR=fillcolor|fillcolour|fc FILLCOLOR=fillcolor|fillcolour|fc
FILLTRANSPARENCY=filltransparency
PENTRANSPARENCY=pentransparency|linetransparency
FILLSTYLE=fillstyle FILLSTYLE=fillstyle
FONTCOLOR=fontcolor|textcolor|textcolour FONTCOLOR=fontcolor|textcolor|textcolour
FONTHEIGHT=fontsize|textsize|textheight FONTHEIGHT=fontsize|textsize|textheight
...@@ -80,6 +82,7 @@ INT=int ...@@ -80,6 +82,7 @@ INT=int
FLOAT=float FLOAT=float
STR=str STR=str
SQRT=sqrt SQRT=sqrt
LOG10=log10
SIN=sin SIN=sin
COS=cos COS=cos
ROUND=round ROUND=round
......
...@@ -143,7 +143,7 @@ ...@@ -143,7 +143,7 @@
<value>300</value> <value>300</value>
</prop> </prop>
</node> </node>
<node oor:name="m10" oor:op="replace"> <node oor:name="m08b" oor:op="replace">
<prop oor:name="Context" oor:type="xs:string"> <prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value> <value>com.sun.star.text.TextDocument</value>
</prop> </prop>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment