gtkforphp / cairo

PHP extension for Cairo Graphics Library
Other
27 stars 19 forks source link

Current PHP7 status #20

Open auroraeosrose opened 9 years ago

auroraeosrose commented 9 years ago

New features added

  1. Matrices have their properties exposed and can be manipulated
  2. Mesh and raster pattern support ( not yet complete)
  3. Rectangles

Changes

  1. Namespaced
  2. License change
  3. Has extension dep
  4. Real enums

Odds and ends

swen100 commented 8 years ago

Hi Elizabeth,

it has become a bit quiet here... Have you found some time to work further? At the beginning you had so much energy, what went wrong?

Is all o.k with you? Are u fine?

Swen

auroraeosrose commented 8 years ago

I have had the fun of house remodeling, a hard drive crashing and taking my vms with it (ugh) and way too much stuff for work :( I'll try to get back on this

swen100 commented 8 years ago

Hi Elizabeth,

i have cloned the project and began to port the code of the files which are still not compatible with PHP7 (surface, context, font,...). I have seen, what you have made and tried to adapt it, so that my changes are as compatible as possible with yours. Please, can u tell me if you have some files for which you have already made something, so that i dont do the same things you have done already.

Recently surface.c and font_options.c got finished and it gives me no compile errors. But you, with your excellent C-knowledge, should take a look on it to find the things i have overseen.

I wil go on further. Please contact me if i should leave some files untouched, if you want to port them.

You can find my tree here: https://github.com/swen100/cairo/tree/php7

Swen

swen100 commented 8 years ago
swen100 commented 8 years ago

Hm, i filled up the method Cairo\Pattern\Surface::getSurface(), but it gives me a segfault and I don't know why...

Another question: should we change the status()-method-names (in Surface, FontFace, FontOptions, ScaledFont, ...) to getStatus() ?

swen100 commented 8 years ago

~~ScaledFont ported, but all methods give me a segfauft :/ Seems to lie within the destructor... Elizabeth where are you? I need your help!~~

auroraeosrose commented 8 years ago

hah, let me take a look :) the biggest issue is teh way you have to emalloc and efree any stored zvals it makes it a little more complex when you're dealing with stuff

swen100 commented 8 years ago

Hi Elizabeth,

i am back from a short vacation. Did you find the cause of the segfaults?

Swen

I think, i solved it on my own. Seems to work fine. Hopefully...

swen100 commented 8 years ago

Ok, I solved the last (known) segfaults. Ready to be fully tested now.

Swen

auroraeosrose commented 8 years ago

aewsome! thank you

swen100 commented 8 years ago

please keep in mind that I changed some method-names.

The difference between "source", "sourceSurface" and "target" was not clear in my opinion. So I changed the names of the following methods to make it clear which type of argument the method expects (or returns):

Cairo/Context::setSourceSurface() --> setSurface( Cairo/Surface ) Cairo/Context::setSource() --> setPattern( Cairo/Pattern ) Cairo/Context::getTarget() --> getSurface() Cairo/Context::getGroupTarget() --> getGroupSurface() Cairo/Context::getSource() --> getPattern()

Additionally these method-names were changed also: Cairo/Context::clipExtents() --> getClipExtents() Cairo/Context::fillExtents() --> getFillExtents() Cairo/Context::pathExtents() --> getPathExtents() Cairo/Context::fontExtents() --> getFontExtents() Cairo/Context::textExtents() --> getTextExtents()

Cairo/ScaledFont::textExtents() --> getTextExtents() Cairo/ScaledFont::glyphExtents() --> getGlyphExtents()

status()-method-names in Surface, FontFace, FontOptions, ScaledFont, ... to getStatus()

auroraeosrose commented 8 years ago

sounds like a good api adjustment - most of the naming was straight from the C methods and used to try to "sync up" with the dual api - but without the dual api a lot of the naming doesn't make sense

auroraeosrose commented 8 years ago

any chance you can start doing some pull requests with parts of this? it's very large as is right now but I'd like to start integrating the new code

swen100 commented 8 years ago

Sure :) Here it comes: #23

weltling commented 7 years ago

@auroraeosrose FYI I've just uploaded the vc14 builds of cairo and accompanying stuff to the PECL deps directory. Was basically waiting for ext/cairo to release, but ext/rrdtool caused to do that as it's already 7.x ported :) Thus, everything should be prepared on Windows side as well, if you decide to release on PECL. OFC you can poke for a snapshot build anytime. Please let me know, if there are any issues with the deps.

Thanks.

Jan-E commented 7 years ago

@weltling The PHP7 branch is not ready for building on Windows.

If you try that the build process first complains about a missing 'php_cairo_api.h'. After adding that file (from the master branch) to the src-directory and changing the PHP_INSTALL_HEADERS lines in config.w32, the configure seems to succeed. But then it ends in

C:\php-sdk\php70dev>nmake php_cairo.dll

Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

NMAKE : fatal error U1073: don't know how to make 'ext\cairo\cairo.c'
Stop.

This is caused by moving most of the files to the src-directory. In short: the php7 branch still needs a lot of fixes before it can be built on Windows.

Jan-E commented 7 years ago

I fixed the php7 config.w32 in https://github.com/gtkforphp/cairo/issues/26

But even if you add the sources of eos_datastructures building fails:


Recreating build dirs
Recreating build dirs
Recreating build dirs
Recreating build dirs
Recreating build dirs
Recreating build dirs
Recreating build dirs
Recreating build dirs
libiconv_a.lib(iconv1.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
   Creating library C:\php-sdk\php70dev\Release_TS\php7ts.lib and object C:\php-sdk\php70dev\Release_TS\php7ts.exp
Generating code
Finished generating code
C:\php-sdk\php70dev\Release_TS\ext\cairo\src/cairo.obj : warning LNK4042: object specified more than once; extras ignored
cairo_a.lib(pixman-image.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
C:\php-sdk\php70dev\Release_TS\ext\cairo\src/cairo.obj : warning LNK4042: object specified more than once; extras ignored
   Creating library C:\php-sdk\php70dev\Release_TS\php_cairo.lib and object C:\php-sdk\php70dev\Release_TS\php_cairo.exp
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
cairo.obj : error LNK2001: unresolved external symbol _zm_startup_cairo_win32_font
region.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
surface.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
svg_surface.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
font_options.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
image_surface.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
pattern.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
ps_surface.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
context.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
exception.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
font.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
font_face.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_ce
context.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_value
exception.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_value
font_options.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_value
pattern.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_get_enum_value
image_surface.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_set_enum_value
pattern.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_set_enum_value
scaled_font.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_set_enum_value
surface.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_set_enum_value
context.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_set_enum_value
font.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_set_enum_value
font_face.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_set_enum_value
font_options.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_set_enum_value
context.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_check_value
font_options.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_check_value
pattern.obj : error LNK2001: unresolved external symbol _php_eos_datastructures_check_value
ft_font.obj : error LNK2001: unresolved external symbol _php_cairo_get_ft_error
C:\php-sdk\php70dev\Release_TS\php_cairo.dll : fatal error LNK1120: 6 unresolved externals
Jan-E commented 7 years ago

New PR: https://github.com/gtkforphp/cairo/pull/27

Jan-E commented 7 years ago

The result of that PR and the PR for eos https://github.com/eosforphp/datastructures/pull/2 : https://phpdev.toolsforresearch.com/php-7.0.15RC1-Win32-VC14-x64.htm https://phpdev.toolsforresearch.com/php-7.0.15RC1-Win32-VC14-x64.zip

Jan-E commented 7 years ago

A friendly ping

swen100 commented 7 years ago

Hi @Jan-E, on your php-info-site (under your link) I have seen, that the Freetype Font-Backend in the cairo-extension is disabled. Please, could you enable it and recompile the extension so that is available? It would be very fantastic because I am using your provided php-package (thank you!) and I got the error "missing class Cairo\FontFace\Ft". I dont want to compile cairo on my own, as Elizabeth wrote long time ago it is a "pain in the ass" :)

Swen

Jan-E commented 7 years ago

I will try to do such. Do not expect it instantly, as I am quite crowded with work ATM. BTW: newer releases are at https://www.apachelounge.com/viewtopic.php?t=6359 and https://www.apachelounge.com/viewtopic.php?t=6617

dirzhov commented 7 years ago

Who have compiled extension for php 7 win64 ts ? Will this extension be located in http://windows.php.net/downloads/pecl/releases/cairo/0.3.2/ ? thanks

Jan-E commented 7 years ago

@weltling :

@auroraeosrose FYI I've just uploaded the vc14 builds of cairo and accompanying stuff to the PECL deps directory. Was basically waiting for ext/cairo to release, but ext/rrdtool caused to do that as it's already 7.x ported :) Thus, everything should be prepared on Windows side as well, if you decide to release on PECL. OFC you can poke for a snapshot build anytime. Please let me know, if there are any issues with the deps.

With https://github.com/gtkforphp/cairo/pull/27 ext/cairo builds for PHP 7 VC14 now. See the AppVeyor builds. I did not use the deps from windows.php.net yet. This will need some extra changes in appveyor.yml to download zlib, freetype, fontconfig, libpng. Maybe we can make those changes after @auroraeosrose has merged https://github.com/gtkforphp/cairo/pull/27

Jan-E commented 7 years ago

BTW: a travis.yml has been missing from the PHP7 branch from the beginning.

The same accounts for cairo_error.c: missing as well. This causes warnings on Windows like warning C4013: 'php_cairo_throw_exception' undefined; assuming extern returning int https://ci.appveyor.com/project/auroraeosrose/cairo/build/1.0.59/job/owxw4k9eo1uj6xx8#L659

These warnings (and maybe more) should be fixed before a new release.

Jan-E commented 7 years ago

Correction: cairo_error.c has been renamed to src/exception.c. php_cairo_throw_exception is there: https://github.com/gtkforphp/cairo/blob/php7/src/exception.c#L34

But php_cairo_api.h was not there. I added the one from master once again in https://github.com/gtkforphp/cairo/pull/27/commits/6d801ef5350d129d68bed155d7bd3ef3d555ba84 as part of https://github.com/gtkforphp/cairo/pull/27

adamdyson commented 7 years ago

Is it possible for someone to create a new release for PHP 7.1? Also is the Pango Wrapper going to be updated?

Jan-E commented 7 years ago

See https://www.apachelounge.com/viewtopic.php?t=6359 The php_cairo.dll's and php_eos_datastructures.dll's are inside my complete build-zips. According to @swen100 they are OK. I do not actively use them myself.

adamdyson commented 7 years ago

@Jan-E I'm running Ubuntu 16.04

Jan-E commented 7 years ago

@swen100

on your php-info-site (under your link) I have seen, that the Freetype Font-Backend in the cairo-extension is disabled. Please, could you enable it and recompile the extension so that is available?

Did you ever try the extension with freetype enabled? See https://www.apachelounge.com/viewtopic.php?t=6359

adamdyson commented 7 years ago

@Jan-E

FYI I was able to compile the bindings with PHP 7.1 on Ubuntu. However tests obviously failed and all example files need re-factoring, I had to look through the source files to determine the namespace\classes to use because there's no docs.

adamdyson commented 7 years ago

@Jan-E

Are the Pango bindings likely to be updated, so they're compatible with PHP 7?

dirzhov commented 7 years ago

Hi! How to use compiled extension for php 7.1.6? I enabled these extensions: extension=php_eos_datastructures.dll extension=php_igbinary.dll extension=php_cairo.dll

And my phpinfo shows: Cairo Graphics Library Bindings enabled compiled as dynamic module Cairo Library Version 1.14.6 Extension Version 1.0.0-dev Surface Backends Available Image Surface enabled PNG Support enabled PDF Surface enabled PS Surface enabled Xlib (X11, X.org) Surface disabled Quartz (MacOSX) Surface disabled SVG Surface enabled Win32 Surface enabled Recording Surface enabled Font Backends Available Freetype Fonts enabled Quartz Fonts disabled Win32 Fonts enabled User Fonts enabled

But i have the error Uncaught Error: Class 'CairoImageSurface' not found in..

adamdyson commented 7 years ago

@dirzhov

Try updating the test file font-matrix-translation.php with the code below. If the example works, there's no issue with compiling the extension, it's simply a problem with your implementation.

<?php

use Cairo\Context;
use Cairo\Matrix;
use Cairo\Surface\Image;
use Cairo\Surface\ImageFormat;

function box_text($str, $x, $y)
{
    global $con;
    $con->save();
    $ext = $con->getTextExtents($str);
    $sf = $con->getScaledFont();
    $sext = $sf->getTextExtents("text");
    $lw = $con->getLineWidth();
    $con->rectangle($x + $ext["x_bearing"]-$lw/2, $y + $ext["y_bearing"] - $lw/2, $ext["width"]+$lw, $ext["height"]+ $lw);
    $con->stroke();
    $con->moveTo($x,$y);
    $con->showText($str);
    $con->restore();
}
$sur = new Image(ImageFormat::ARGB32, 38, 34);
$con = new Context($sur);

$con->setSourceRgb(1,1,1);
$con->paint();

$con->selectFontFace("Bitstream Vera Sans");
$con->setFontSize(12);
$con->translate(4,4);
$con->setLineWidth(1);
$ext = $con->getTextExtents("text");

$con->setSourceRgb(0,0,0);
box_text("text", 0, -$ext["y_bearing"]);
$mat = new Matrix();
$mat->translate(6,16);
$mat->scale(12,12);
$con->setFontMatrix($mat);
$con->setSourceRgb(0,0,1);
box_text("text", 0, -$ext["y_bearing"]);

$sur->writeToPng(dirname(__FILE__)  . "/font-matrix-translation-php-svg.png");
dirzhov commented 7 years ago

Yes, your code is working. Looks like functionality from old api is not compatible with new. http://php.net/manual/en/refs.utilspec.image.php Need to map from old dll CairoImageSurface => Image CairoContext => Context

I printed list of available classes from cairo library: [161] => Cairo\Pattern [162] => Cairo\Pattern\Solid [163] => Cairo\Pattern\Gradient [164] => Cairo\Pattern\Gradient\Radial [165] => Cairo\Pattern\Gradient\Linear [166] => Cairo\Pattern\Surface [167] => Cairo\Pattern\Mesh [168] => Cairo\Pattern\RasterSource [169] => Cairo\Pattern\Type [170] => Cairo\Extend [171] => Cairo\Filter [172] => Cairo\Rectangle [173] => Cairo\Matrix [174] => Cairo\Exception [175] => Cairo\Status [176] => Cairo\Region [177] => Cairo\Region\Overlap [178] => Cairo\FontFace [179] => Cairo\FontType [180] => Cairo\FontFace\Toy [181] => Cairo\FontSlant [182] => Cairo\FontWeight [183] => Cairo\FontOptions [184] => Cairo\Antialias [185] => Cairo\SubPixelOrder [186] => Cairo\HintStyle [187] => Cairo\HintMetrics [188] => Cairo\ScaledFont [189] => Cairo\FontFace\Ft [190] => Cairo\FontFace\Win32 [191] => Cairo\FontFace\Win32\FontWeight [192] => Cairo\FontFace\Win32\FontCharset [193] => Cairo\FontFace\Win32\FontOutputPrecision [194] => Cairo\FontFace\Win32\FontClipPrecision [195] => Cairo\FontFace\Win32\FontQuality [196] => Cairo\FontFace\Win32\FontPitch [197] => Cairo\FontFace\Win32\FontFamily [198] => Cairo\Surface [199] => Cairo\Surface\Content [200] => Cairo\Surface\Type [201] => Cairo\Surface\Image [202] => Cairo\Surface\ImageFormat [203] => Cairo\Surface\SubSurface [204] => Cairo\Surface\Recording [205] => Cairo\Surface\Pdf [206] => Cairo\Surface\Svg [207] => Cairo\Surface\Svg\Version [208] => Cairo\Surface\Ps [209] => Cairo\Surface\Ps\Level [210] => Cairo\Path [211] => Cairo\Context [212] => Cairo\FillRule [213] => Cairo\LineCap [214] => Cairo\LineJoin [215] => Cairo\Operator

Is there documentation somewhere about new api?

adamdyson commented 7 years ago

@dirzhov

Good to hear you got it working. Yes the documentation is outdated and it's not compatible with PHP 7 since its more or less a complete rewrite, with namespaces being introduced and API methods changing (see the comments above by @swen100 ). I'd imagine it may be a while before we see the documentation updated, the test cases would likely need to be updated first.

@Jan-E @swen100 is updating the test cases something I can help with?

auroraeosrose commented 7 years ago

most of the API changes are just name mappings to get the items namespaced The other "big" change is having enum classes

I'm happy to pull any prs with test and example changes

Also a helper file for translating old code would be great - a simple array of old => new class names could be used for string replace madness :)

adamdyson commented 7 years ago

@auroraeosrose Ok I'll make a fork and begin updating the examples in my spare time. Sorry to nag, but any idea when/if the Pango bindings will be updated? I would attempt it myself but my knowledge of C is poor.

Jan-E commented 7 years ago

@auroraeosrose

I'm happy to pull any prs with test and example changes

Could you merge https://github.com/gtkforphp/cairo/pull/27 please? I'm using that one to build php_cairo.dll for PHP 7.0, 7.1 and 7.2 on Windows.

auroraeosrose commented 7 years ago

pulled - still some outstanding issues but we can't pin them all down until tests and examples are ported :)

Jan-E commented 7 years ago

Sorry to nag, but any idea when/if the Pango bindings will be updated?

I am not going to do it. If somebody gets it done, I will be happy to compile it for Windows. That should be possible, I guess: https://github.com/weltling/php-pango/commits/master

Jan-E commented 7 years ago

@auroraeosrose Thx

auroraeosrose commented 7 years ago

ping @mgdm someone does want the port of pango

Jan-E commented 7 years ago

FWIW: the imagick extension supports the pango format. And it is actively maintained: https://github.com/mkoppanen/imagick/commits/master

adamdyson commented 7 years ago

@Jan-E Thanks, unfortunately I'm wanting to export to SVG which rules out Imagick.

dirzhov commented 7 years ago

I rendered gif image with the php 7.1.6 and cairo extension. Looks like images are rendered with the strange red points on green arcs. Here is example https://media.giphy.com/media/l0Iym3YPooou0SeSA/giphy.gif Under php 5.6 I have the same image, but without points, all arcs were clear.

adamdyson commented 7 years ago

See pull request https://github.com/gtkforphp/cairo/pull/30

mhertsch commented 7 years ago

Can someone confirm, that the bitmap-font.php example is not working? I get the following error:

php bitmap-font.php
PHP Fatal error:  Uncaught TypeError: Value 2 provided is not a const in enum Cairo\HintMetrics in /home/Develop/cairo/examples/bitmap-font.php:19
Stack trace:
#0 /home/Develop/cairo/examples/bitmap-font.php(19): Cairo\FontOptions->setHintMetrics(2)
#1 {main}
  thrown in /home/Develop/cairo/examples/bitmap-font.php on line 19

ImageFormat enum works for me, but the HintMetrics and HintStyle in this example do not.

Also, when I compare the large-font-php output to the expected I get two not matching pictures.

PHP_VERSION : 7.1.8 ZEND_VERSION: 3.1.0 PHP_OS : Linux - Linux php7centos 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64

adamdyson commented 7 years ago

@mhertsch see my pull request. The updated example is correct, but there's currently issues with Enums in the code base that need to be fixed.

mhertsch commented 7 years ago

@adamdyson ok. I do remember reading #30, but not looking that deep into #29. Should have done that :(

At least for the examples this seems like a comprehensive issue list, but I am wondering, if we have a complete open issues list. Like for example the current expected status of 'make test'. I get 300+ skiped tests and some fails, but I am not sure, if this is an issue with my CentOS 7 php71 enviornment or just the current state of development.