/*!
Get left margin, page offset

\param y offset ( optional )
\return left margin
184396
function leftMargin( $yOffset = false )
    {
        $maxMargin = $this->ez['leftMargin'];

        if ( $yOffset === false )
        {
            $yOffset = $this->yOffset();
        }

        foreach ( $this->LeftMarginArray as $leftMargin )
        {
            if ( $yOffset > $leftMargin['start'] &&
                 $yOffset < $leftMargin['stop']  &&
                 $leftMargin['margin'] > $maxMargin )
            {
                $maxMargin = $leftMargin['margin'];
            }
        }

        return $maxMargin;
    }
1134784
function _getOffset(element) {
    var elementPosition = {};

    var body = document.body;
    var docEl = document.documentElement;

    var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
    var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;

    if (element instanceof SVGElement) {
        var x = element.getBoundingClientRect();
        elementPosition.top = x.top + scrollTop;
        elementPosition.width = x.width;
        elementPosition.height = x.height;
        elementPosition.left = x.left + scrollLeft;
    } else {
        //set width
        elementPosition.width = element.offsetWidth;

        //set height
        elementPosition.height = element.offsetHeight;

        //calculate element top and left
        var _x = 0;
        var _y = 0;
        while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {
            _x += element.offsetLeft;
            _y += element.offsetTop;
            element = element.offsetParent;
        }
        //set top
        elementPosition.top = _y;
        //set left
        elementPosition.left = _x;
    }

    return elementPosition;
}
1273161
function PRVTgetTextPosition( $x, $y, $angle, $size, $wa, $text )
    {
        $tmp = false;
        // given this information return an array containing x and y for the end position as elements 0 and 1

        $w = $this->getTextWidth($size,$text);
        // need to adjust for the number of spaces in this text
        $words = explode(' ',$text);
        $nspaces=count($words)-1;
        $w += $wa*$nspaces;
        $a = deg2rad((float)$angle);
        if ( $tmp )
        {
            return array($this->xOffset(),-sin($a)*$w+$y);
        }
        return array(cos($a)*$w+$x,-sin($a)*$w+$y);
    }
195003
function (e) {
            // This code is inspired from https://stackoverflow.com/a/3464890
            var doc = document.documentElement,
                pageX = e.clientX + (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0),
                pageY = e.clientY + (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
            return { X: pageX, Y: pageY };
        }
956350
function () {
                    var rect = this._anchorElement.getBoundingClientRect();

                    return {
                        x: rect.left,
                        y: rect.top,
                        width: rect.width,
                        height: rect.height
                    };
                }
276759
function pageOffset(el) {
        var curleft = 0, curtop = 0;
        if (el.offsetParent) {
            do {
                curleft += el.offsetLeft;
                curtop += el.offsetTop;
            } while (el = el.offsetParent);
        }
        return [curleft, curtop];
    }
1154425
function offset(el) {
  const rect = el.getBoundingClientRect();
  const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;

  return {
    top: rect.top + scrollTop,
    left: rect.left + scrollLeft
  };
}
197077
function(margin) {
      if (!this.length) {
        return 0;
      }
      return margin ? this[0].offsetWidth + parseInt(getComputedStyle(this[0]).marginLeft) + parseInt(getComputedStyle(this[0]).marginRight) : this[0].offsetWidth;
    }
1258590
function() {
		var yOffset = _panOffset.y - self.currItem.initialPosition.y; // difference between initial and current position
		return 1 -  Math.abs( yOffset / (_viewportSize.y / 2)  );
	}
836355
function getOffsetParent(node) {
		var offsetParent = node.parentNode, documentElement = document.documentElement;
		while (offsetParent && offsetParent !== documentElement) {
			var style = window.getComputedStyle(offsetParent, null);
			if (!style) { break; }
			var overflow = style.getPropertyValue("overflow-y"); //$NON-NLS-0$
			if (overflow === "auto" || overflow === "scroll") { break; } //$NON-NLS-1$ //$NON-NLS-0$
			offsetParent = offsetParent.parentNode;
		}
		return offsetParent;
	}
1050292
function callFrameLine( $info )
    {
        $parameters = array();
        eZPDFTable::extractParameters( $info['p'], 0, $parameters, true );

        $location = $parameters['location'];
        $yOffset = $parameters['margin'];
        if ( $location == 'frame_header' )
        {
            $yOffset = $this->ez['pageHeight'] - $parameters['margin'];
        }

        $rightMargin = $this->rightMargin( $yOffset );
        if ( isset( $parameters['rightMargin'] ) )
        {
            $rightMargin = $parameters['rightMargin'];
        }

        $leftMargin = $this->leftMargin( $yOffset );
        if ( isset( $parameters['leftMargin'] ) )
        {
            $leftMargin = $parameters['leftMargin'];
        }

        $this->setLineStyle( $parameters['thickness'] );

        reset( $this->ezPages );
        foreach ( $this->ezPages as $pageNum => $pageID )
        {
            if( $pageNum < $parameters['pageOffset'] )
                continue;

            if ( $parameters['page'] == 'odd' &&
                 $pageNum % 2 == 0 )
                continue;

            if ( $parameters['page'] == 'even' &&
                 $pageNum % 2 == 1 )
                continue;

            $this->reopenObject( $pageID );
            $this->line( $leftMargin, $yOffset, $this->ez['pageWidth'] - $rightMargin, $yOffset );
            $this->closeObject();
        }

        $this->setLineStyle( 1 );
    }
717800
function get_min_max_width()
    {
        if (!is_null($this->_min_max_cache)) {
            return $this->_min_max_cache;
        }

        $style = $this->_frame->get_style();

        // Account for margins & padding
        $dims = array($style->padding_left,
            $style->padding_right,
            $style->border_left_width,
            $style->border_right_width,
            $style->margin_left,
            $style->margin_right);

        $cb_w = $this->_frame->get_containing_block("w");
        $delta = (float)$style->length_in_pt($dims, $cb_w);

        // Handle degenerate case
        if (!$this->_frame->get_first_child()) {
            return $this->_min_max_cache = array(
                $delta, $delta,
                "min" => $delta,
                "max" => $delta,
            );
        }

        $low = array();
        $high = array();

        for ($iter = $this->_frame->get_children()->getIterator(); $iter->valid(); $iter->next()) {
            $inline_min = 0;
            $inline_max = 0;

            // Add all adjacent inline widths together to calculate max width
            while ($iter->valid() && in_array($iter->current()->get_style()->display, Style::$INLINE_TYPES)) {
                $child = $iter->current();

                $minmax = $child->get_min_max_width();

                if (in_array($iter->current()->get_style()->white_space, array("pre", "nowrap"))) {
                    $inline_min += $minmax["min"];
                } else {
                    $low[] = $minmax["min"];
                }

                $inline_max += $minmax["max"];
                $iter->next();
            }

            if ($inline_max > 0) {
                $high[] = $inline_max;
            }
            if ($inline_min > 0) {
                $low[] = $inline_min;
            }

            if ($iter->valid()) {
                list($low[], $high[]) = $iter->current()->get_min_max_width();
                continue;
            }
        }
        $min = count($low) ? max($low) : 0;
        $max = count($high) ? max($high) : 0;

        // Use specified width if it is greater than the minimum defined by the
        // content.  If the width is a percentage ignore it for now.
        $width = $style->width;
        if ($width !== "auto" && !Helpers::is_percent($width)) {
            $width = (float)$style->length_in_pt($width, $cb_w);
            if ($min < $width) {
                $min = $width;
            }
            if ($max < $width) {
                $max = $width;
            }
        }

        $min += $delta;
        $max += $delta;
        return $this->_min_max_cache = array($min, $max, "min" => $min, "max" => $max);
    }
128809
def _offset(self, x, y):
        """"""
        x, y = force_int(x, y)
        return y * self.width * 4 + x * 4
67405
function coordsChar(x, y) {
      var th = textHeight(), cw = charWidth(), heightPos = displayOffset + Math.floor(y / th);
      if (heightPos < 0) return {line: 0, ch: 0};
      var lineNo = lineAtHeight(doc, heightPos);
      if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc.size - 1).text.length};
      var lineObj = getLine(lineNo), text = lineObj.text;
      var tw = options.lineWrapping, innerOff = tw ? heightPos - heightAtLine(doc, lineNo) : 0;
      if (x <= 0 && innerOff == 0) return {line: lineNo, ch: 0};
      var wrongLine = false;
      function getX(len) {
        var sp = measureLine(lineObj, len);
        if (tw) {
          var off = Math.round(sp.top / th);
          wrongLine = off != innerOff;
          return Math.max(0, sp.left + (off - innerOff) * scroller.clientWidth);
        }
        return sp.left;
      }
      var from = 0, fromX = 0, to = text.length, toX;
      // Guess a suitable upper bound for our search.
      var estimated = Math.min(to, Math.ceil((x + innerOff * scroller.clientWidth * .9) / cw));
      for (;;) {
        var estX = getX(estimated);
        if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
        else {toX = estX; to = estimated; break;}
      }
      if (x > toX) return {line: lineNo, ch: to};
      // Try to guess a suitable lower bound as well.
      estimated = Math.floor(to * 0.8); estX = getX(estimated);
      if (estX < x) {from = estimated; fromX = estX;}
      // Do a binary search between these bounds.
      for (;;) {
        if (to - from <= 1) {
          var after = x - fromX < toX - x;
          return {line: lineNo, ch: after ? from : to, after: after};
        }
        var middle = Math.ceil((from + to) / 2), middleX = getX(middle);
        if (middleX > x) {to = middle; toX = middleX; if (wrongLine) toX += 1000; }
        else {from = middle; fromX = middleX;}
      }
    }
108086
function (node) {
    var x = document.documentElement.offsetLeft,
        y = document.documentElement.offsetTop;

    if (node.offsetParent || document.body) {
        do {
            x += node.offsetLeft;
            y += node.offsetTop;
        } while (node = node.offsetParent);
    }

    return {x: x, y: y};
}
1301085
def leftAt(self, offset=0):
        
        return Location(self.getX() + offset, self.getY() + (self.getH() / 2))
1341699
function (elem, offsetParent) {
  var offset, parentOffset

  if (window.jQuery) {
    if (!offsetParent) {
      return window.jQuery(elem).position()
    }

    offset = window.jQuery(elem).offset()
    parentOffset = window.jQuery(offsetParent).offset()

    // Get element offset relative to offsetParent
    return {
      top: offset.top - parentOffset.top,
      left: offset.left - parentOffset.left
    }
  }

  parentOffset = { top: 0, left: 0 }

  // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
  if (window.getComputedStyle(elem).position === 'fixed' ) {
    // We assume that getBoundingClientRect is available when computed position is fixed
    offset = elem.getBoundingClientRect()
  }
  else {
    if (!offsetParent) {
      // Get *real* offsetParent
      offsetParent = position.offsetParent(elem)
    }

    // Get correct offsets
    offset = offsetFunc(elem)
    if (offsetParent.nodeName !== 'HTML') {
      parentOffset = offsetFunc(offsetParent)
    }

    // Add offsetParent borders
    parentOffset.top += parseInt(window.getComputedStyle(offsetParent).borderTopWidth, 10)
    parentOffset.left += parseInt(window.getComputedStyle(offsetParent).borderLeftWidth, 10)
  }

  // Subtract parent offsets and element margins
  return {
    top: offset.top - parentOffset.top - parseInt(window.getComputedStyle(elem).marginTop, 10),
    left: offset.left - parentOffset.left - parseInt(window.getComputedStyle(elem).marginLeft, 10)
  }
}