You are here

public static function PHPExcel_Shared_Excel5::oneAnchor2twoAnchor in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/Excel5.php \PHPExcel_Shared_Excel5::oneAnchor2twoAnchor()

* Convert 1-cell anchor coordinates to 2-cell anchor coordinates * This function is ported from PEAR Spreadsheet_Writer_Excel with small modifications * * Calculate the vertices that define the position of the image as required by * the OBJ record. * * +------------+------------+ * | A | B | * +-----+------------+------------+ * | |(x1,y1) | | * | 1 |(A1)._______|______ | * | | | | | * | | | | | * +-----+----| BITMAP |-----+ * | | | | | * | 2 | |______________. | * | | | (B2)| * | | | (x2,y2)| * +---- +------------+------------+ * * Example of a bitmap that covers some of the area from cell A1 to cell B2. * * Based on the width and height of the bitmap we need to calculate 8 vars: * $col_start, $row_start, $col_end, $row_end, $x1, $y1, $x2, $y2. * The width and height of the cells are also variable and have to be taken into * account. * The values of $col_start and $row_start are passed in from the calling * function. The values of $col_end and $row_end are calculated by subtracting * the width and height of the bitmap from the width and height of the * underlying cells. * The vertices are expressed as a percentage of the underlying cell width as * follows (rhs values are in pixels): * * x1 = X / W *1024 * y1 = Y / H *256 * x2 = (X-1) / W *1024 * y2 = (Y-1) / H *256 * * Where: X is distance from the left side of the underlying cell * Y is distance from the top of the underlying cell * W is the width of the cell * H is the height of the cell * *

Parameters

PHPExcel_Worksheet $sheet: * @param string $coordinates E.g. 'A1' * @param integer $offsetX Horizontal offset in pixels * @param integer $offsetY Vertical offset in pixels * @param integer $width Width in pixels * @param integer $height Height in pixels * @return array

1 call to PHPExcel_Shared_Excel5::oneAnchor2twoAnchor()
PHPExcel_Writer_Excel5::_buildWorksheetEschers in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5.php
* Build the Worksheet Escher objects *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/Excel5.php, line 245

Class

PHPExcel_Shared_Excel5
PHPExcel_Shared_Excel5

Code

public static function oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height) {
  list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinates);
  $col_start = PHPExcel_Cell::columnIndexFromString($column) - 1;
  $row_start = $row - 1;
  $x1 = $offsetX;
  $y1 = $offsetY;

  // Initialise end cell to the same as the start cell
  $col_end = $col_start;

  // Col containing lower right corner of object
  $row_end = $row_start;

  // Row containing bottom right corner of object
  // Zero the specified offset if greater than the cell dimensions
  if ($x1 >= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start))) {
    $x1 = 0;
  }
  if ($y1 >= self::sizeRow($sheet, $row_start + 1)) {
    $y1 = 0;
  }
  $width = $width + $x1 - 1;
  $height = $height + $y1 - 1;

  // Subtract the underlying cell widths to find the end cell of the image
  while ($width >= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end))) {
    $width -= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end));
    ++$col_end;
  }

  // Subtract the underlying cell heights to find the end cell of the image
  while ($height >= self::sizeRow($sheet, $row_end + 1)) {
    $height -= self::sizeRow($sheet, $row_end + 1);
    ++$row_end;
  }

  // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
  // with zero height or width.
  if (self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) == 0) {
    return;
  }
  if (self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) == 0) {
    return;
  }
  if (self::sizeRow($sheet, $row_start + 1) == 0) {
    return;
  }
  if (self::sizeRow($sheet, $row_end + 1) == 0) {
    return;
  }

  // Convert the pixel values to the percentage value expected by Excel
  $x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024;
  $y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
  $x2 = ($width + 1) / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024;

  // Distance to right side of object
  $y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256;

  // Distance to bottom of object
  $startCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_start) . ($row_start + 1);
  $endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1);
  $twoAnchor = array(
    'startCoordinates' => $startCoordinates,
    'startOffsetX' => $x1,
    'startOffsetY' => $y1,
    'endCoordinates' => $endCoordinates,
    'endOffsetX' => $x2,
    'endOffsetY' => $y2,
  );
  return $twoAnchor;
}