// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See https://js.arcgis.com/4.8/esri/copyright.txt for details.
//>>built
define(["require","exports"],function(y,z){return function(){function n(d,c,e,a,h,l,b,f){this._glyphItems=d;this._maxWidth=c;this._lineHeight=e;this._letterSpacing=a;this._offset=h;this._hAnchor=l;this._vAnchor=b;this._justify=f}n.prototype.getShaping=function(d,c){for(var e=this._letterSpacing,a=this._lineHeight,h=this._justify,l=this._maxWidth,b=[],f=0,k=0,g=0,m=0,r=-1,t=0,n=-1,x=d.length,v=0;v<x;v++){var w=d.charCodeAt(v);if(10===w){if(v!==x-1){if(r>=m){var f=b[r],p=f.x+f.glyphMosaicItem.metrics.advance,
t=Math.max(p,t);h&&this._applyJustification(b,m,r);m=b.length}k=c?k-a:k+a;f=0;++g}}else{for(var p=void 0,u=0,q=this._glyphItems;u<q.length&&!(p=q[u][w]);u++);if(p){b.push({codePoint:w,x:f,y:k,glyphMosaicItem:p});f+=p.metrics.advance+e;if(0<l&&f>l&&0<=n){u=n+1;p=b[u].x;t=Math.max(p,t);for(q=u;q<b.length;q++)b[q].y=c?b[q].y-a:b[q].y+a,b[q].x-=p;h&&this._applyJustification(b,m,n);k=c?k-a:k+a;f-=p;++g;m=u;n=-1}++r;32===w&&(n=b.length-1)}}}r>=m&&(f=b[r],t=Math.max(t,f.x+f.glyphMosaicItem.metrics.advance),
h&&this._applyJustification(b,m,r));if(0<b.length)for(d=(h-this._hAnchor)*t,e=(-this._vAnchor*(g+1)+.5)*a,c&&g&&(e+=g*a),d+=this._offset[0],e+=this._offset[1],c=0;c<b.length;c++)a=b[c],a.x+=d,a.y+=e;return b};n.getBox=function(d,c){var e=d.length;if(0!==e){for(var a=d[0].x,h=a,l=d[0].y,b=l,f=l,k=1;k<e;k++){var g=d[k],m=g.x;m<a&&(a=m);m>h&&(h=m);g=g.y;g<l&&(l=g);g>b&&(b=g);g!==f&&(f=this._glyphWidth(d[k-1].codePoint,c),h=Math.max(h,d[k-1].x+f),f=g)}c=this._glyphWidth(d[e-1].codePoint,c);h=Math.max(h,
d[e-1].x+c);l+=17;return{x:a,y:l,width:h-a,height:b+7-l}}};n.prototype._applyJustification=function(d,c,e){for(var a=d[e],a=(a.x+a.glyphMosaicItem.metrics.advance)*this._justify;c<=e;c++)d[c].x-=a};n._glyphWidth=function(d,c){for(var e,a=0;a<c.length&&!(e=c[a][d]);a++);return e?e.metrics.advance:0};return n}()});