コード例 #1
0
$cr2->lineTo(0, 5 * $patheight / 6.0);
$cr2->setSourceRgb(0, 1, 0);
$cr2->stroke();
$cr2->moveTo(5 * $patwidth / 6.0, 0);
$cr2->lineTo($patwidth, 0);
$cr2->lineTo($patwidth, $patheight / 6.0);
$cr2->setSourceRgb(0, 0, 1);
$cr2->stroke();
$cr2->moveTo(5 * $patwidth / 6.0, $patheight);
$cr2->lineTo($patwidth, $patheight);
$cr2->lineTo($patwidth, 5 * $patheight / 6.0);
$cr2->setSourceRgb(1, 1, 0);
$cr2->stroke();
$cr2->setSourceRgb(0.5, 0.5, 0.5);
$cr2->setLineWidth($patwidth / 10.0);
$cr2->moveTo(0, $patheight / 4.0);
$cr2->lineTo($patwidth, $patheight / 4.0);
$cr2->stroke();
$cr2->moveTo($patwidth / 4.0, 0);
$cr2->lineTo($patwidth / 4.0, $patwidth);
$cr2->stroke();
$pattern = new CairoSurfacePattern($pat_surface);
$mat = new CairoMatrix();
$mat->scale(2, 1.5);
$mat->rotate(1);
$mat->translate(-$patwidth / 4.0, -$patwidth / 2.0);
$pattern->setMatrix($mat);
$pattern->setExtend(CairoExtend::NONE);
$con->setSource($pattern);
$con->paint();
$sur->writeToPng(dirname(__FILE__) . "/meta-surface-pattern-php.png");
コード例 #2
0
ファイル: self-copy.php プロジェクト: jamesan/cairo
<?php

$size = 40;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $size, $size);
$con = new CairoContext($sur);
$con->setSourceRgb(1, 1, 1);
/* White */
$con->paint();
$con->moveTo($size, 0);
$con->lineTo($size, $size);
$con->lineTo(0, $size);
$con->setSourceRgb(0, 0, 0);
$con->fill();
/* Create a pattern with the target surface as the source,
 * offset by $size/2 */
$pattern = new CairoSurfacePattern($sur);
$matrix = new CairoMatrix();
$matrix->translate(-$size / 2, -$size / 2);
$pattern->setMatrix($matrix);
$con->setSource($pattern);
/* Copy two rectangles from the upper-left quarter of the image to
 * the lower right.  It will work if we use $con->fill(), but the
 * $con->clip() $con->paint() combination fails because the clip
 * on the surface as a destination affects it as the source as
 * well.
 */
$con->rectangle(2 * $size / 4, 2 * $size / 4, $size / 4, $size / 4);
$con->rectangle(3 * $size / 4, 3 * $size / 4, $size / 4, $size / 4);
$con->clip();
$con->paint();
$sur->writeToPng(dirname(__FILE__) . '/self-copy.png');
コード例 #3
0
ファイル: mask-ctm.php プロジェクト: jamesan/cairo
<?php

$sur = new CairoImageSurface(CairoFormat::ARGB32, 10, 10);
$con = new CairoContext($sur);
$data = "";
for ($i = 0; $i < 4; $i++) {
    $data = $data . chr(0x80);
    $data = $data . chr(0x0);
    $data = $data . chr(0x0);
    $data = $data . chr(0x0);
}
$s = new CairoImageSurface(CairoFormat::ARGB32, 1, 1);
$s->createForData(data, CairoFormat::ARGB32, 2, 2, 8);
$pat = new CairoSurfacePattern($s);
$con->setSourceRgb(1, 0, 0);
$con->save();
$con->translate(2, 2);
$con->mask($pat);
$con->restore();
$mat = new CairoMatrix();
$mat->translate(-4, -4);
$pat->setMatrix($mat);
$con->mask($pat);
$con->translate(2, 2);
$con->mask($pat);
$sur->writeToPng(dirname(__FILE__) . "/mask-ctm-php.png");
?>



コード例 #4
0
    $ext = $con->textExtents($str);
    $sf = $con->getScaledFont();
    $sext = $sf->textExtents("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 CairoImageSurface(CairoFormat::ARGB32, 38, 34);
$con = new CairoContext($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->textExtents("text");
$con->setSourceRgb(0, 0, 0);
box_text("text", 0, -$ext["y_bearing"]);
$mat = new CairoMatrix();
$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.png");
?>