PS ps_translate
(PECL ps >= 1.1.0)
ps_translate — Sets translation
설명
ps_translate(resource $psdoc
, float $x
, float $y
): bool
좌표계의 새 초기점을 설정합니다.
매개변수
psdoc
- ps_new()에 의해 반환된 포스트스크립트 파일의 리소스 식별자입니다.
x
- 변환된 좌표계 원점의 x 좌표입니다.
y
- 변환된 좌표계 원점의 y 좌표입니다.
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
Examples
예제 #1 좌표계의 변환
<?php
function rectangle($ps) {
ps_moveto($ps, 0, 0);
ps_lineto($ps, 0, 50);
ps_lineto($ps, 50, 50);
ps_lineto($ps, 50, 0);
ps_lineto($ps, 0, 0);
ps_stroke($ps);
}
$ps = ps_new();
if (!ps_open_file($ps, "translate.ps")) {
print "Cannot open PostScript file\n";
exit;
}
ps_set_info($ps, "Creator", "translate.php");
ps_set_info($ps, "Author", "Uwe Steinmann");
ps_set_info($ps, "Title", "Translated example");
ps_set_info($ps, "BoundingBox", "0 0 596 842");
$psfont = ps_findfont($ps, "Helvetica", "", 0);
ps_begin_page($ps, 596, 842);
ps_set_text_pos($ps, 100, 100);
ps_translate($ps, 500, 750);
rectangle($ps);
ps_translate($ps, -500, -750);
ps_setfont($ps, $psfont, 8.0);
ps_show($ps, "Text at initial position");
ps_end_page($ps);
ps_begin_page($ps, 596, 842);
ps_set_text_pos($ps, 100, 100);
ps_save($ps);
ps_translate($ps, 500, 750);
rectangle($ps);
ps_restore($ps);
ps_setfont($ps, $psfont, 8.0);
ps_show($ps, "Text at initial position");
ps_end_page($ps);
ps_delete($ps);
?>
위의 예는 그래픽 자체가 자체 좌표계를 사용하는 동안 페이지의 임의의 위치에 그래픽(이 경우 직사각형)을 배치하는 두 가지 가능한 방법을 보여줍니다. 트릭은 직사각형을 그리기 전에 현재 좌표계의 원점을 변경하는 것입니다. 그래픽을 그린 후에 번역을 취소해야 합니다.
두 번째 페이지에서는 약간 다르게 더 우아한 접근 방식이 적용됩니다. 두 번째 ps_translate() 호출로 변환을 실행 취소하는 대신 좌표계를 수정하기 전에 그래픽 컨텍스트를 저장하고 사각형을 그린 후 복원합니다.
기타
- ps_scale() - Sets scaling factor
- ps_rotate() - Sets rotation factor