NAME
CSS::Yamaantaka - Converts direction of Cascading Style Sheet (CSS)
SYNOPSIS
use CSS::Yamaantaka;
$ya = CSS::Yamaantaka->new('lr_tb' => 'tb_rl');
$css_source_vertical_rl = $ya->transform($css_source);
DESCRIPTION
As Yamāntaka has many legs, texts can run in various directions: left to right and right to left horizontally; vertically with lines extending right to left and left to right.
CSS::Yamaantaka replaces things directed to "left" or "horizontal-tb" in a Cascading Style Sheet (CSS) file such as float, padding, margin with values directed to "right" or "vertical-rl", and so on.
Constructor
- new ( SRC => DEST, [ options... ] )
- new (
'adaptor'=> ADAPTOR, [ options... ] ) -
Creates new CSS::Yamaantaka object.
In first form, SRC and DEST are the original and resulting directions. Available directions are
'lr_tb','rl_tb','tb_lr'and'tb_rl'. Their synonyms are'ltr','rtl','vertical-lr'and'vertical-rl', respectively.Following options are available.
- flip_bg => 0|1
-
Fixes background positions properties. Default is
1, will fix. - flip_cursor => 0|1
-
Fixes positions "n"/"e"/"s"/"w" and so on within cursor properties. Default is
1, will fix. - flip_url => 0|1
-
Fixes "top"/"right"/"bottom"/"left" string within URLs. Default is
0, won't fix. - ignore_bad_bgp => 0|1
-
Ignores unmirrorable background-position values. Default is
1, WILL ignore and won't croak it. - swap_ltr_rtl_in_url => 0|1
-
Fixes "ltr"/"rtl" string within URLs, if needed. Default is
0, won't fix.
In second form, ADAPTOR is a name of package or an object. package will be automatically loaded. See "Adaptors" about standard adaptors.
Methods
- body_direction
-
Get direction property or dir attribute of body element thought to be appropriate. Returns
'ltr','rtl'or undef (unknown).
- text_orientation
-
Get text-orientation property of texts assumed. Returns
'sideways-left'or undef (upright or sideways-right is assumed).
- transform ( $lines, [ options... ] )
-
Runs the fixing functions against CSS source.
$lines is a string. Following options are available.
- flip_bg => 0|1
- flip_cursor => 0|1
- flip_url => 0|1
- swap_ltr_rtl_in_url => 0|1
-
Overrides these flags if params are set.
Returns same lines directions are changed.
- writing_mode
-
Get writing-mode property of texts thought to be appropriate. Returns
'horizontal-tb','vertical-lr','vertical-rl'or undef (unknown).
Adaptors
This module supports four directions of documents:
- lr-tb
-
The direction specified by
{ direction: ltr; writing-mode: horizontal-tb; }. For example, most Western writing systems employ it. - rl-tb
-
The direction specified by
{ direction: rtl; writing-mode: horizontal-tb; }. For example, some Middle Eastern writing systems employ it. - tb-lr
-
The direction specified by
{ writing-mode: vertical-lr; }. For example, several North Asian writing systems employ it. - lr-tb
-
The direction specified by
{ writing-mode: vertical-rl; }. East Asian writing systems with vertical layout employ it.
This module chooses adaptors by source & resulting directions:
table 1. Choosing adaptors
+-----------+-------------+-------------+-------------+--------------+
| from \ to | lr-tb : rl-tb : tb-lr : tb-rl |
+-----------+-------------+-------------+-------------+--------------+
| lr-tb | - : MirrorH : MirrorTL_BR : RotateR |
| rl-tb | MirrorH : - : RotateL* : MirrorTR_BL* |
| tb-lr | MirrorTL_BR : RotateR : - : MirrorV |
| tb-rl | RotateL : MirrorTR_BL : MirrorV : - |
+-----------+-------------+-------------+-------------+--------------+
* Assumed text-orientation: sideways-left.
n.b.: Prefixing "CSS::Yamaantaka::" are omitted.
Each adaptor will or won't change following "directions" of CSS properties.
- line-relative box directions
-
"right" / "left" of text-align, float and clear. "top" / "bottom" of vertical-align.
- physical box directions
-
"top" / "right" / "bottom" / "left".
- global directions
-
Directions specified by body element, "ltr" / "rtl".
- direction swapping
-
Horizontal and vertical orientation.
table 2. Feature of adaptors
+-------------+-----------+-------------------------+---------+------+
| | line-rel. | box directions : global : h/v |
+-------------+-----------+-------------------------+---------+------+
| MirrorH | reverse h.: reverse horizontally : reverse : - |
| MirrorV | - : reverse horizontally : reverse : - |
| RotateR | - : rotate clockwise : reverse : swap |
| RotateL | - : rotate counter-clockwise: reverse : swap |
| MirrorTL_BR | - : reverse with tl-br axis : - : swap |
| MirrorTR_BL | - : reverse with tr-bl axis : - : swap |
+-------------+-----------+-------------------------+---------+------+
Any adaptors listed above won't fix line-relative text directions ("rtl" / "ltr").
VERSION
Consult $VERSION variable.
SEE ALSO
Extended CSSJanus supporting vertical-rl writing-mode: http://www.epubcafe.jp/download
AUTHOR
Hatuka*nezumi - IKEDA Soji <hatuka(at)nezumi.nu>.
COPYRIGHT
Copyright (C) 2013 Hatuka*nezumi - IKEDA Soji.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.