コード例 #1
0
 /**
  * Utility function to create an array of position styles and convert to a string.
  * @param IdmlElement $element
  * @param float $left
  * @param float $top
  * @param string $vertRefPoint - used only for embedded elements
  * @return string representation of styles
  */
 public function getStyleString(IdmlElement $element, $left, $top, $vertRefPoint)
 {
     // Create and populate the array with position, left, and top
     $styles = array('position' => 'absolute');
     // Assign final left and top offset values
     if (!is_null($left)) {
         $styles['left'] = $left . 'px';
     }
     // Don't supply a top value for an embedded element if the VerticalReferencePoint is unsupported.
     if (!$element->isEmbedded() || !is_null($top) && !in_array($vertRefPoint, array('LineBaseline', 'Capheight', 'TopOfLeading'))) {
         $styles['top'] = $top . 'px';
     }
     // Now convert the array to a string and return it.
     $styleString = "";
     foreach ($styles as $name => $value) {
         if (strlen($value) > 0) {
             $styleString .= sprintf("%s:%s;", $name, $value);
         }
     }
     return trim($styleString);
 }