예제 #1
0
 /**
  * @param null $source
  */
 public function addAutomaticStyle(ODTStyle $new)
 {
     $name = $new->getProperty('style-name');
     if ($this->auto_styles_by_name[$name] == NULL) {
         $this->auto_styles[] = $new;
         if (!empty($name)) {
             $this->auto_styles_by_name[$name] = $new;
         }
         return true;
     }
     // Do not overwrite an already existing style.
     return false;
 }
예제 #2
0
 /**
  * @param null $source
  */
 public function addStyleInternal(&$dest, &$dest_by_name, ODTStyle $new, $overwrite = false)
 {
     if ($new->isDefault()) {
         // The key for a default style is the family.
         $family = $new->getFamily();
         // Search for default style with same family.
         for ($index = 0; $index < count($dest); $index++) {
             if ($dest[$index]->isDefault() && $dest[$index]->getFamily() == $family) {
                 // Only overwrite it if allowed.
                 if ($overwrite) {
                     $dest[$index] = $new;
                 }
                 return false;
             }
         }
         // Default style for that family does not exist yet, add it.
         $dest[] = $new;
     } else {
         // The key for a normal style is the name.
         $name = $new->getProperty('style-name');
         if ($dest_by_name[$name] == NULL) {
             $dest[] = $new;
             if (!empty($name)) {
                 $dest_by_name[$name] = $new;
             }
             return true;
         } elseif ($overwrite) {
             for ($index = 0; $index < count($dest); $index++) {
                 if ($dest[$index] == $dest_by_name[$name]) {
                     $dest[$index] = $new;
                     break;
                 }
             }
             $dest_by_name[$name] = $new;
             return true;
         }
     }
     // Do not overwrite an already existing style.
     return false;
 }