コード例 #1
0
 function TbsPicPrepare(&$Txt, &$Loc, $IsCaching)
 {
     if (isset($Loc->PrmLst['pic_prepared'])) {
         return true;
     }
     if (isset($Loc->PrmLst['att'])) {
         return $this->RaiseError('Parameter att is used with parameter ope=changepic in the field [' . $Loc->FullName . ']. changepic will be ignored');
     }
     $backward = true;
     if (isset($Loc->PrmLst['tagpos'])) {
         $s = $Loc->PrmLst['tagpos'];
         if ($s == 'before') {
             $backward = false;
         } elseif ($s == 'inside') {
             if ($this->ExtType == 'openxml') {
                 $backward = false;
             }
         }
     }
     // Find the target attribute
     $att = false;
     if ($this->ExtType === 'odf') {
         $att = 'draw:image#xlink:href';
     } elseif ($this->ExtType === 'openxml') {
         $att = $this->OpenXML_FirstPicAtt($Txt, $Loc->PosBeg, $backward);
         if ($att === false) {
             return $this->RaiseError('Parameter ope=changepic used in the field [' . $Loc->FullName . '] has failed to found the picture.');
         }
     } else {
         return $this->RaiseError('Parameter ope=changepic used in the field [' . $Loc->FullName . '] is not supported with the current document type.');
     }
     // Move the field to the attribute
     // This technical works with cached fields because already cached fields are placed before the picture.
     $prefix = $backward ? '' : '+';
     $Loc->PrmLst['att'] = $prefix . $att;
     clsTinyButStrong::f_Xml_AttFind($Txt, $Loc, true);
     // Delete parameter att to prevent TBS from another processing
     unset($Loc->PrmLst['att']);
     // Get picture dimension information
     if (isset($Loc->PrmLst['adjust'])) {
         $FieldLen = 0;
         if ($this->ExtType === 'odf') {
             $Loc->otbsDim = $this->TbsPicGetDim_ODF($Txt, $Loc->PosBeg, false, $Loc->PosBeg, $FieldLen);
         } else {
             if (strpos($att, 'v:imagedata') !== false) {
                 $Loc->otbsDim = $this->TbsPicGetDim_OpenXML_vml($Txt, $Loc->PosBeg, false, $Loc->PosBeg, $FieldLen);
             } else {
                 $Loc->otbsDim = $this->TbsPicGetDim_OpenXML_dml($Txt, $Loc->PosBeg, false, $Loc->PosBeg, $FieldLen);
             }
         }
     }
     // Set the original picture to empty
     if (isset($Loc->PrmLst['unique']) && $Loc->PrmLst['unique']) {
         // Get the value in the template
         $Value = substr($Txt, $Loc->PosBeg, $Loc->PosEnd - $Loc->PosBeg + 1);
         if ($this->ExtType === 'odf') {
             $InternalPicPath = $Value;
         } elseif ($this->ExtType === 'openxml') {
             $InternalPicPath = $this->OpenXML_GetInternalPicPath($Value);
             if ($InternalPicPath === false) {
                 $this->RaiseError('The picture to merge with field [' . $Loc->FullName . '] cannot be found. Value=' . $Value);
             }
         }
         // Set the picture file to empty
         $this->FileReplace($InternalPicPath, '', TBSZIP_STRING, false);
     }
     $Loc->PrmLst['pic_prepared'] = true;
     return true;
 }