<commit_before>goog.provide('ngeo.PrintUtils');

goog.require('ngeo');


/**
 * Provides a service with print utility functions.
 *
 * @constructor
 * @ngdoc service
 * @ngname ngeoPrintUtils
 */
ngeo.PrintUtils = function() {
};


/**
 * @const
 * @private
 */
ngeo.PrintUtils.INCHES_PER_METER_ = 39.37;


/**
 * @const
 * @private
 */
ngeo.PrintUtils.DOTS_PER_INCH_ = 72;


/**
 * Return a function to use as map postcompose listener for drawing a print
 * mask on the map.
 * @param {function():ol.Size} getSize User-defined function returning the
 *     size in dots of the map to print.
 * @param {function(olx.FrameState):number} getScale User-defined function
 *     returning the scale of the map to print.
 * @param {function():number=} opt_rotation User defined function returning the
 *     inclination of the canevas in degree (-180 to 180).
 * returning the scale of the map to print.
 * @return {function(ol.render.Event)} Function to use as a map postcompose
 * listener.
 * @export
 */
ngeo.PrintUtils.prototype.createPrintMaskPostcompose = function(getSize,
    getScale, opt_rotation) {
  var self = this;

  return (
      /**
       * @param {ol.render.Event} evt Postcompose event.
       */
      function(evt) {
        var context = evt.context;
        var frameState = evt.frameState;

        var resolution = frameState.viewState.resolution;

        var viewportWidth = frameState.size[0] * frameState.pixelRatio;
        var viewportHeight = frameState.size[1] * frameState.pixelRatio;

        var center = [viewportWidth / 2, viewportHeight / 2];

        var size = getSize();
        var scale = getScale(frameState);

        var ppi = ngeo.PrintUtils.DOTS_PER_INCH_;
        var ipm = ngeo.PrintUtils.INCHES_PER_METER_;

        var extentHalfWidth =
            (((size[0] / ppi) / ipm) * scale / resolution) / 2;
        self.extentHalfHorizontalDistance_ =
            (((size[0] / ppi) / ipm) * scale) / 2;

        var extentHalfHeight =
            (((size[1] / ppi) / ipm) * scale / resolution) / 2;
        self.extentHalfVerticalDistance_ =
            (((size[1] / ppi) / ipm) * scale) / 2;

        // Draw a mask on the whole map.
        context.beginPath();
        context.moveTo(0, 0);
        context.lineTo(viewportWidth, 0);
        context.lineTo(viewportWidth, viewportHeight);
        context.lineTo(0, viewportHeight);
        context.lineTo(0, 0);
        context.closePath();

        // Draw the print zone
        if (!opt_rotation) {
          self.drawPrintZone_(context, center, extentHalfWidth,<commit_msg>Take device pixel ratio when displaying print mask (#1634)<commit_after>goog.provide('ngeo.PrintUtils');

goog.require('ngeo');


/**
 * Provides a service with print utility functions.
 *
 * @constructor
 * @ngdoc service
 * @ngname ngeoPrintUtils
 */
ngeo.PrintUtils = function() {
};


/**
 * @const
 * @private
 */
ngeo.PrintUtils.INCHES_PER_METER_ = 39.37;


/**
 * @const
 * @private
 */
ngeo.PrintUtils.DOTS_PER_INCH_ = 72;


/**
 * Return a function to use as map postcompose listener for drawing a print
 * mask on the map.
 * @param {function():ol.Size} getSize User-defined function returning the
 *     size in dots of the map to print.
 * @param {function(olx.FrameState):number} getScale User-defined function
 *     returning the scale of the map to print.
 * @param {function():number=} opt_rotation User defined function returning the
 *     inclination of the canevas in degree (-180 to 180).
 * returning the scale of the map to print.
 * @return {function(ol.render.Event)} Function to use as a map postcompose
 * listener.
 * @export
 */
ngeo.PrintUtils.prototype.createPrintMaskPostcompose = function(getSize,
    getScale, opt_rotation) {
  var self = this;

  return (
      /**
       * @param {ol.render.Event} evt Postcompose event.
       */
      function(evt) {
        var context = evt.context;
        var frameState = evt.frameState;

        var resolution = frameState.viewState.resolution;

        var viewportWidth = frameState.size[0] * frameState.pixelRatio;
        var viewportHeight = frameState.size[1] * frameState.pixelRatio;

        var center = [viewportWidth / 2, viewportHeight / 2];

        var size = getSize();
        var height = size[1] * ol.has.DEVICE_PIXEL_RATIO;
        var width = size[0] * ol.has.DEVICE_PIXEL_RATIO;
        var scale = getScale(frameState);

        var ppi = ngeo.PrintUtils.DOTS_PER_INCH_;
        var ipm = ngeo.PrintUtils.INCHES_PER_METER_;

        var extentHalfWidth =
            (((width / ppi) / ipm) * scale / resolution) / 2;
        self.extentHalfHorizontalDistance_ =
            (((size[0] / ppi) / ipm) * scale) / 2;

        var extentHalfHeight =
            (((height / ppi) / ipm) * scale / resolution) / 2;
        self.extentHalfVerticalDistance_ =
            (((size[1] / ppi) / ipm) * scale) / 2;

        // Draw a mask on the whole map.
        context.beginPath();
        context.moveTo(0, 0);
        context.lineTo(viewportWidth, 0);
        context.lineTo(viewportWidth, viewportHeight);
        context.lineTo(0, viewportHeight);
        context.lineTo(0, 0);
        context.closePath();

        // Draw the print zone
        if (!opt_rotation) {
          self.drawPrintZone_(context, center, extentHalfWidth,
{'fraction_non_alphanumeric': 0.11634923628135017, 'fraction_numerical': 0.012068640392230812, 'mean_word_length': 2.6204778156996587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3920315', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1628, 'n_words': 435}