Giter VIP home page Giter VIP logo

drawbot-skia's Introduction

Run tests

drawbot-skia

A Python package implementing a subset of the DrawBot API using Skia as a backend.

Work in progress!

Roadmap

  1. Get basic shapes working ✅
  2. Get basic colors working ✅
  3. Get minimal BezierPath object working ✅
  4. Get transformations working ✅
  5. Get single-line, single style text() working ✅
  6. Get Variable Fonts working ✅
  7. Get HarfBuzz shaping working ✅
  8. Get OpenType features working ✅
  9. Get PNG, JPEG image export working ✅
  10. Get PDF export working ✅
  11. Get MP4 export working ✅
  12. Get SVG export working ✅
  13. Get Animated GIF export working
  14. Get multi-line, single style text() working
  15. Get FormattedString working
  16. Get multi-style text() working
  17. Get remaining BezierPath methods working
  18. Get many-things-I-forgot-to-mention working
  19. ...
  20. textBox() 🔴 (Major Obstacle)
  21. Fill further gaps in DrawBot API

The currently supported subset of Drawbot is tracked here.

Vision

This project is purely a Python package that implements (part of) the DrawBot drawing API. Using Skia (skia-python) ensures this can be done in a cross-platform way.

A DrawBot-like cross-platform application shell can be developed, but that would be a separate project. Looking forward to the drawbot-qt, drawbot-wx, drawbot-win or any drawbot-* projects of the future!

Compatibility caveats

Some parts of the DrawBot API will be hard or impractical to duplicate.

Skia has only low level support for text, so we'll have to do Unicode processing, line wrapping, hyphenation, and shaping ourselves. In other words, textBox() will be a tough one to crack.

Generally, 100% text compatibility with DrawBot should not be top priority, as matching CoreText behavior will be a huge challenge.

The ImageObject relies heavily on builtin macOS functionality, and it is huge. At best, we should support a small subset of it, but even that is low priority.

Strategy

So far no existing DrawBot code has been reused. Perhaps that small snippets will be copied, perhaps a part of the test suite will be adapted. Other than that I want this to be an independent project, and would like to use Skia’s powers to maximum effect, keeping efficiency and performance in mind. DrawBot's ties to macOS are so strong that it makes platform-neutral code reuse virtually impossible.

Potentially, some higher level code could be shared (for example, drawing code that uses lower level primitives), but that will have to been seen later.

Install

The quickest way to install the latest release is with pip:

pip install drawbot-skia

Note for Windows: skia-python is only supported for the 64-bit version of Python, so that goes for drawbot-skia as well, so make sure you use one of the x86-64 Python installers.

If you want to see the source code and possibly contribute: clone the repo, and do pip install -e . in the root directory.

Usage

To adapt a DrawBot script to drawbot-skia you can do a couple of things:

  • Add from drawbot_skia.drawbot import * at the top of your script
  • Or import drawbot_skia.drawbot as db if that's your preferred style

Or you can use the drawbot runner tool from the command line:

  • drawbot mydrawbotscript.py output.png

With the drawbot runner tool, you won't need any Drawbot import in the script, nor do you need a saveImage(...) to export results. It pretty much behaves as if you hit "Run" in the classic Drawbot application.

drawbot-skia's People

Contributors

jansindl3r avatar jenskutilek avatar justvanrossum avatar pyup-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drawbot-skia's Issues

blendMode SVG looks wrong

the svg output of blendMode is quite different from the other outputs, and looks wrong.
it happens on rendering for me, and is the same in the apitests_expected_output.

integration in jupyter notebook?

hi and thanks for the great work. i installed it yesterday on debian and everything seems to work well.

is there any way to integrate it in a jupyter notebook, as it is the case for the matplotlib? or what is your normal workflow in coding and watching the result?

cheers -
joachim

drawbot-skia and Django

Hey Just, this kind of left field. I have ported some drawbot code to drawbot-skia for use on a website. I use Django as my webserver. When I run the drawbot-skia code through a Django view and get it to output a skia SVG, it will output the file. Reload the page and it will output another file with a number variation. Reload again and it just keeps going. If I manually delete those files and reload the page. All the files that I have deleted are but back. Do this too quickly and you get the following warning:

drawbot_skia.errors.DrawbotError: size() can't be called if there's already a canvas active

It is odd that it is saying the canvas is still active even thought there is del canvas in the _def saveImage_svg()

I feel that this file behaviour has something to do with the FILEWStream part. Like it leaves the stream open or something. Because the underlying python-skia library is in C it is impossible for me to figure out what is going on. Outside of Django this works fine.

So I know this is a vague question but have you seen this behaviour before? Any idea why it might be doing this? Ultimately I would just like to grab the SVG and put it in the HTML page.

Talk soon, Maarten

tracking supported?

i miss the tracking method to work with text, as described in drawbot://www.drawbot.com/_downloads/tracking.py
are there any plans to implement it?
or is it already implemented under a different name?

drawBot compatibility test

would writing tests checking stuff like these between drawbot-skia and drawbot be desirable?

rect.__code__.co_argcount
rect.__defaults__
rect.__code__.co_varnames

if yes, I would like to do it!

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

The subset of Drawbot that is currently supported

Currently supported Drawbot functions:

  • size(width, height)
  • newPage(width, height)
  • frameDuration(duration)
  • width()
  • height()
  • rect(x, y, w, h)
  • oval(x, y, w, h)
  • line(pt1, pt2)
  • polygon(firstPoint, *points, close=True)
  • drawPath(path)
  • clipPath(path)
  • fill(*args)
  • stroke(*args)
  • strokeWidth(value)
  • lineCap(lineCap)
  • lineJoin(lineJoin)
  • lineDash(firstValue, *values)
  • blendMode(blendMode)
  • miterLimit(miterLimit)
  • linearGradient(...)
  • radialGradient(...) limited to a single center point and a zero start radius
  • font(fontNameOrPath, fontSize=None)
  • fontSize(size)
  • openTypeFeatures(*, resetFeatures=False, **features)
  • fontVariations(*, resetVariations=False, **variations)
  • textSize(txt)
  • language(language)
  • text(txt, position, align=None) single line, single style only for now
  • image(imagePath, position, alpha=1.0) limited to pixel formats, PDF is not supported
  • translate(x, y)
  • rotate(angle, center=(0, 0))
  • scale(sx, sy=None, center=(0, 0))
  • skew(sx, sy=0, center=(0, 0))
  • transform(matrix, center=(0, 0))
  • savedState()
  • saveImage(fileName) currently limited to PNG, JPG, MP4 and PDF

BezierPath currently supports:

  • path.moveTo(pt)
  • path.lineTo(pt)
  • path.curveTo(pt1, pt2, pt3, *pts)
  • path.qCurveTo(pt1, pt2, *pts)
  • path.arc(center, radius, startAngle, endAngle, clockwise)
  • path.arcTo(point1, point2, radius)
  • path.closePath()
  • path.endPath() segment pen method / point pen method
  • path.beginPath() point pen method
  • path.addPoint(...) point pen method
  • path.rect(x, y, w, h)
  • path.oval(x, y, w, h)
  • path.polygon(firstPoint, *points, close=True)
  • path.text(txt, ...)
  • path.pointInside(point)
  • path.bounds()
  • path.controlPointBounds()
  • path.appendPath(other)
  • path.copy()
  • path.reverse()
  • path.translate(x, y)
  • path.scale(x, y=None, center=(0, 0))
  • path.rotate(angle, center=(0, 0))
  • path.skew(x, y=0, center=(0, 0))
  • path.transform(transform, center=(0, 0))
  • path.drawToPen(pen)
  • path.drawToPointPen(pen)
  • path.removeOverlap()
  • path.union(other) and path.__or__(other)
  • path.intersection(other) and path.__and__(other)
  • path.difference(other) and path.__mod__(other)
  • path.xor(other) and path.__xor__(other)

For an overview of changes and additions per release, see https://github.com/justvanrossum/drawbot-skia/blob/master/CHANGELOG.md

functions not possible?

i cannot get functions to use, for instance:

def myline(x1,y1,x2,y2):
line((x1,x2),(y1,y2))

size(700,250)
myline(100,100,200,50)

no error, but also no output.

i also tried different variants, like:

def myline(x1,y1,x2,y2):
path = BezierPath()
path.line((x1,y1),(x2,y2))
path.closePath()
drawPath(path)

am i missing anything, or is this simply not supposed to work?

newPage() requires arguments

newPage() requires argument, though mac's drawbot doesn't. This breaks compatibility of code that can be shared in class for both drawbot app and drawbot-skia. Is it intentional? Can I make a PR?

Error while import drawbot_skia

Hi! I just installed Drawbot Skia and I got this error:

Traceback (most recent call last):
  File "./test.py", line 3, in <module>
    from drawbot_skia.drawbot import *
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/drawbot_skia/drawbot.py", line 1, in <module>
    from .drawing import Drawing
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/drawbot_skia/drawing.py", line 4, in <module>
    import skia
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/skia.cpython-37m-darwin.so, 2): Symbol not found: _XML_ErrorString
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/skia.cpython-37m-darwin.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/skia.cpython-37m-darwin.so

This is my script

from drawbot_skia.drawbot import *

rect(100, 100, 100, 100)
saveImage('test.jpeg')

And I runned it with python ./test.py

Am I doing something wrong? I’m on OS: Mac Os Mojave 10.14.6

Dependency issues

First, pillow is required to run the test suite and doesn't seem to be mentioned as a test dependency anywhere. I must be blind, it's right there in requirements-dev.txt.

Second it seems numpy should be listed as a test dependency, not as a regular dependency. It is used directly for tests. I looked through the skip-python code based and it seems the same there, it is never used directly in the library but it is used for the test suite. As such they seem to have it specified properly and the only improper thing is where this shows up and moving it to test deps would be appropriate:

"numpy", # unlisted skia-python dependency, TODO: is this true?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.