标签: cairo

如何在Gtk下创建一个cairo-gl表面

我想在linux(fedora 12)下使用GTK 3创建一个窗口,并使用cairo-gl后端在其上绘制一个简单的矩形,为此我想创建一个cairo-gl表面.我怎么能这样做,任何人都可以帮我提供示例代码.

提前致谢.

RC7

cairo gtk3

9
推荐指数
1
解决办法
3266
查看次数

pyCairo:如何调整图像大小和位置?

基于使用Pycairo创建PDF(调整大小)PNG图像的问题 - 重新缩放Surface问题我试图创建重新调整图像并将图像放置在特定位置的代码,如下面的代码所示(在本例中,例如,图像应显示在"基础矩形"的"上方".但是,我似乎无法让图像显示在正确的位置.

我很高兴知道我必须改变什么,以便正确地缩放定位图像.

import cairo
if not cairo.HAS_PDF_SURFACE:
    raise SystemExit('cairo was not compiled with PDF support')


def draw_image(ctx, image, top, left, height, width):
    """Draw a scaled image on a given context."""
    image_surface = cairo.ImageSurface.create_from_png(image)
    # calculate proportional scaling
    img_height = image_surface.get_height()
    img_width = image_surface.get_width()
    width_ratio = float(width) / float(img_width)
    height_ratio = float(height) / float(img_height)
    scale_xy = min(height_ratio, width_ratio)
    # scale image and add it
    ctx.save()
    ctx.scale(scale_xy, scale_xy)
    ctx.translate(left, top)
    ctx.set_source_surface(image_surface)

    ctx.paint()
    ctx.restore()


def …
Run Code Online (Sandbox Code Playgroud)

python cairo pycairo

9
推荐指数
1
解决办法
6949
查看次数

如何在Windows上安装cairo

对于我的生活,我无法弄清楚如何在Windows上安装cairo!

我需要它用于Haskell图表,但是当我按照设置说明运行时:

cabal install gtk
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Linking dist/setup-wrapper\setup.exe ...
Configuring glib-0.12.2...
setup.exe: The program pkg-config version >=0.9.0 is required but it could not
be found.
cabal.exe: Error: some packages failed to install:
cairo-0.12.2 failed during the configure step. The exception was:
ExitFailure 1
gio-0.12.2 depends on glib-0.12.2 which failed to install.
glib-0.12.2 failed during the configure step. The exception was:
ExitFailure 1
gtk-0.12.2 depends on glib-0.12.2 which failed to install.
pango-0.12.2 depends on glib-0.12.2 which failed to install. …
Run Code Online (Sandbox Code Playgroud)

haskell cairo cabal

9
推荐指数
1
解决办法
1万
查看次数

如何使用Homebrew安装Py2Cairo等Python库

这是我到目前为止所做的:

我安装了Homebrew:

/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
Run Code Online (Sandbox Code Playgroud)

然后是python: brew install python

然后py2cairo: brew install py2cairo

这两个似乎都正确安装,当我输入which python我得到:usr/local/bin/python我认为是自制的版本.

我已经编辑了我的路径,正如许多Homebrew指南所建议的那样:

export PATH=/usr/local/bin:/usr/local/share/python:$PATH
Run Code Online (Sandbox Code Playgroud)

这是我得到的echo $PATH:/usr/local/bin:/usr/local/share/python:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

我也可以输入python --version并获得python 2.7.3哪些似乎正确,因为如果我查看/usr/local/Cellar/py2cairo/1.10.0/README它说:

Dependencies
------------
    cairo   >= 1.10.0
    Python  >= 2.6 
Run Code Online (Sandbox Code Playgroud)

然而,毕竟这仍然无法将py2cairo库导入python.这是我尝试时得到的:

Sal:~ Lockyer$ python
Python 2.7.3 (default, May  6 2012, 13:47:31) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> …
Run Code Online (Sandbox Code Playgroud)

python homebrew cairo

9
推荐指数
1
解决办法
4781
查看次数

将pdf与300dpi位图转换为svg

我正在创建一个将pdf转换为svg的工具.这些pdf包含图形数据,包括300 dpi的大位图和一堆矢量.周围戳这里计算器,我发现pdf2svg,这伟大的-就像一个魅力,矢量数据是完美的.但看起来位图缩小到72dpi.尺寸仍然是8x10英寸,但是当你放大时你可以看出dpi是不对的.柔和的意义是默认值假设72 dpi,但我需要全分辨率位图图像.

pdf2svg使用poppler和cairo进行转换.我在代码中探讨了一下,我看到它在哪里创建一个poppler页面和一个cairo表面,我在文档中看到一个poppler页面有一个"scale"的概念似乎相关,但我可以'找出插入的位置.我尝试(通过实验)将传入的高度和宽度硬编码为cairo_svg_surface_create正确的值,但它使尺寸应用于整个svg更大,而不影响嵌入的位图.

poppler_page_get_size (page, &width, &height);

// Open the SVG file
surface = cairo_svg_surface_create(svgFilename, width, height);
drawcontext = cairo_create(surface);

// Render the PDF file into the SVG file
poppler_page_render(page, drawcontext);
cairo_show_page(drawcontext);
Run Code Online (Sandbox Code Playgroud)

我不认为我想做的事情是非常深奥的,所以我希望有图书馆经验的人能立刻看到我的错误.当然,任何帮助都会受到极大的赞赏.

c pdf svg poppler cairo

9
推荐指数
1
解决办法
989
查看次数

cairo可以使用SDL_Texture作为渲染目标吗?

使用Cairo可以渲染到SDL_Surface,但我的应用程序使用SDL_Renderer和SDL_Texture来利用2D加速渲染.

我目前正在创建一个SDL_Surface并将其复制到纹理中SDL_CreateTextureFromSurface(),但这个过程很麻烦且可能很慢(尽管它不是瓶颈.)是否有直接的方法来绘制SDL_Texture?

sdl cairo sdl-2

9
推荐指数
1
解决办法
2061
查看次数

在Ubuntu中安装最新的cairo lib for weasyprint

我刚刚安装了一个Ubuntu仿生实例。它预装了cairo 1.14.6。我至少需要cairo 1.15.4才能使weasyprint正常工作。不幸的是,即使在安装了最新的cairo之后,python仍然会选择旧的库。任何线索,我将不胜感激。

# Install weasyprint dependencies
sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info

# Check cairo lib version, prints "1.15.10-2ubuntu0.1"
dpkg -l '*cairo*'

# Install weasyprint
pip3 install weasyprint

# Test cairo version catch by python, still prints "1.14.6"
python3 -c "import cairocffi; print(cairocffi.cairo_version_string())"
Run Code Online (Sandbox Code Playgroud)

python ubuntu cairo python-3.x weasyprint

9
推荐指数
1
解决办法
223
查看次数

将.SVG图像放入tkinter Frame

我一直在尝试将来自https://betacssjs.chesscomfiles.com/bundles/web/favicons/safari-pinned-tab.f387b3f2.svg的图像放入Tkinter框架。我从这里的帖子中发现,在rsvg和cairo的帮助下,这是可能的。

我使用python 3.6在Windows 10,我RSVG从这里和开罗这里,然后提取该文件夹复制到“C:\用户\ site_packages”文件夹。他们进口罚款,但我不知道如何使用它们。我尝试使用代码:

import tkinter as tk
main=tk.Tk()
frame=tk.Frame(main)
def svgPhotoImage(self,file_path_name):
        from PIL import Image,ImageTk
        import rsvg,cairo 
        svg = rsvg.Handle(file=file_path_name)
        width, height = svg.get_dimension_data()[:2]
            surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
            context = cairo.Context(surface)
            #context.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
            svg.render_cairo(context)
            tk_image=ImageTk.PhotoImage('RGBA')
            image=Image.frombuffer('RGBA',(width,height),surface.get_data(),'raw','BGRA',0,1)
            tk_image.paste(image)
            return(tk_image)
    tk_image=self.svgPhotoImage(filename)
    frame.configure(image=tk_image)
Run Code Online (Sandbox Code Playgroud)

#rsvg.py
import os
try:
    import rsvg
    WINDOWS=False
except ImportError:
    print"Warning, could not import 'rsvg'"
    if os.name == 'nt':
        print "Detected windows, creating rsvg."
        #some workarounds for windows

        from ctypes …
Run Code Online (Sandbox Code Playgroud)

python tkinter cairo rsvg python-3.x

9
推荐指数
2
解决办法
773
查看次数

Weasyprint 在调用 write_pdf 时获得未定义的属性:“AttributeError:‘PosixPath’对象没有属性‘read_text’”

我正在 ubuntu 18.04 上运行 weasyprint 项目,并尝试创建 aa pdf。

当我尝试设置页脚图像时,问题就开始了。我正在 python 3.6.7 上运行

这是我调用 weasyprint 的代码:

import sys
import os
from weasyprint import HTML, CSS

htmlFile = sys.argv[1]
pdfFile = sys.argv[2]

html = HTML(filename=htmlFile)

css = CSS(string='@page { @bottom-center { width: 125%; margin-top: 10px; content: " "; background-image: url(file://' + os.getcwd() + '/pdf/footer.png); background-repeat: no-repeat; background-position: right;  background-size: 100%; } }')

html.write_pdf(pdfFile, stylesheets=[css])
Run Code Online (Sandbox Code Playgroud)

但后来我收到以下错误:

Error: Command failed: python3 /node_modules/my-project/python/run.py /node_modules/my-project/pdf/catalog_01e299a3-1fca-482b-a512-e1bea832559f.html /node_modules/my-project/pdf/catalog_01e299a3-1fca-482b-a512-e1bea832559f.pdf
Traceback (most recent call last):
File "/node_modules/my-project/python/run.py", line 3, in …
Run Code Online (Sandbox Code Playgroud)

python cairo weasyprint ubuntu-18.04

8
推荐指数
1
解决办法
1万
查看次数

在使用适用于 macOS 的 GitHub Actions 进行测试之前如何安装 X11?

我正在使用 GitHub Actions 测试 R 包,它在 Windows 和 Linux 上成功。

但是,它在 Mac OS 上失败,正如您在日志中看到的那样:

  Warning in grSoftVersion() :
    unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so':
    dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib
    Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/modules/R_X11.so
    Reason: image not found
  Warning in cairoVersion() :
    unable to load shared object '/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so':
    dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so, 6): Library not loaded: /opt/X11/lib/libXrender.1.dylib
    Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/grDevices/libs/cairo.so
    Reason: image not found
  Warning in png(filename = file, width = width, height = height, units = "in",  :
    failed to load …
Run Code Online (Sandbox Code Playgroud)

x11 macos r cairo github-actions

8
推荐指数
1
解决办法
884
查看次数

标签 统计

cairo ×10

python ×5

python-3.x ×2

weasyprint ×2

c ×1

cabal ×1

github-actions ×1

gtk3 ×1

haskell ×1

homebrew ×1

macos ×1

pdf ×1

poppler ×1

pycairo ×1

r ×1

rsvg ×1

sdl ×1

sdl-2 ×1

svg ×1

tkinter ×1

ubuntu ×1

ubuntu-18.04 ×1

x11 ×1