accent.js 31.2 KB
Newer Older
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1 2
"use strict";

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 0x300  accent grave
// 0x301  accent acute
// 0x307  one dot
// 0x308  two dots
// 0x20DB three dots
// 0x332  single line
// 0x333  double line
// 0x303  tilde
// 0x302  circumflex
// 0x306  breve
// 0x20D6 left arrow
// 0x20D7 right arrow
// 0x20D0 half left arrow (harpoon)
// 0x20D1 half right arrow (harpoon)

Anna.Pavlova's avatar
Anna.Pavlova committed
18 19 20 21 22 23 24
function CAccentCircumflex()
{
    CGlyphOperator.call(this);
}
extend(CAccentCircumflex, CGlyphOperator);
CAccentCircumflex.prototype.calcSize = function(stretch)
{
25
    var alpha = this.Parent.Get_CompiledCtrPrp().FontSize/36;
Anna.Pavlova's avatar
Anna.Pavlova committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

    var width = 3.88*alpha;
    var height = 3.175*alpha;

    var augm = 0.9*stretch/width;

    if(augm < 1)
        augm = 1;
    else if (augm > 5)
        augm = 5;

    width *= augm;

    return {width: width, height: height};
}
CAccentCircumflex.prototype.calcCoord = function(stretch)
{
43
    var fontSize = this.Parent.Get_CompiledCtrPrp().FontSize;
Anna.Pavlova's avatar
Anna.Pavlova committed
44 45 46 47 48 49 50 51
    //var penW = fontSize*g_dKoef_pt_to_mm*this.PEN_W;
    //penW *= 96/25.4;

    // g_dKoef_px_to_mm = 25.4/96

    var textScale = fontSize/1000, // 1000 pt
        alpha = textScale*25.4/96 /64;

52 53
    var X = [],
        Y = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
54 55 56 57 58 59 60 61 62 63 64 65

    X[0] = 0; Y[0] = 2373;
    X[1] = 9331; Y[1] = 15494;
    X[2] = 14913; Y[2] = 15494;
    X[3] = 23869; Y[3] = 2373;
    X[4] = 20953; Y[4] = 0;
    X[5] = 12122; Y[5] = 10118;
    X[6] = 11664; Y[6] = 10118;
    X[7] = 2833; Y[7] = 0;
    X[8] = 0; Y[8] = 2373;


66 67
    var XX = [],
        YY = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
68 69 70 71 72 73 74

    var W = stretch/alpha;

    var a1 = X[3] - X[0], b1 = W,            c1 = X[2] - X[1],
        a2 = X[4] - X[7], b2 = W - 2*X[7],   c2 = X[5] - X[6] ; //X[8] = 0


75
    var RX = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    for(var i = 0; i < X.length; i++)
        RX[i] = 1;

    RX[0] = RX[2] = (b1 - c1)/(a1-c1);
    RX[4] = RX[6] =  (b2 - c2)/(a2-c2);


    XX[0] = XX[8] = X[0];
    YY[0] = YY[8] = Y[0];

    for(var i = 0; i< 4; i++)
    {
        XX[1 + i] = XX[i] + RX[i]*(X[1+i] - X[i]);
        XX[7-i]   = XX[8 - i] + RX[7-i]*(X[7-i] - X[8-i]);
        YY[1+i] = Y[1+i];
        YY[7-i] = Y[7-i];
    }

    for(var i = 0; i < XX.length; i++)
    {
        XX[i] = XX[i]*alpha ;
        YY[i] = YY[i]*alpha;
    }

    var H = YY[1];
    W = XX[3];

    return {XX: XX, YY: YY, W: W, H: H};
}
CAccentCircumflex.prototype.drawPath = function(pGraphics, XX, YY)
{
    pGraphics._m(XX[0], YY[0]);
    pGraphics._l(XX[1], YY[1]);
    pGraphics._l(XX[2], YY[2]);
    pGraphics._l(XX[3], YY[3]);
    pGraphics._l(XX[4], YY[4]);
    pGraphics._l(XX[5], YY[5]);
    pGraphics._l(XX[6], YY[6]);
    pGraphics._l(XX[7], YY[7]);
    pGraphics._l(XX[8], YY[8]);
    pGraphics._l(XX[9], YY[9]);
    pGraphics._l(XX[10], YY[10]);
    pGraphics._l(XX[11], YY[11]);
}
Anna.Pavlova's avatar
Anna.Pavlova committed
120

Anna.Pavlova's avatar
Anna.Pavlova committed
121 122 123 124 125 126 127
function CAccentLine()
{
    CGlyphOperator.call(this);
}
extend(CAccentLine, CGlyphOperator);
CAccentLine.prototype.calcSize = function(stretch)
{
128
    var alpha = this.Parent.Get_CompiledCtrPrp().FontSize/36;
Anna.Pavlova's avatar
Anna.Pavlova committed
129 130 131 132 133 134 135 136 137 138

    var height = 1.68*alpha;
    var width  = 4.938*alpha;

    width = stretch > width ? stretch : width;

    return {width: width, height: height};
}
CAccentLine.prototype.calcCoord = function(stretch)
{
139
    var fontSize = this.Parent.Get_CompiledCtrPrp().FontSize;
Anna.Pavlova's avatar
Anna.Pavlova committed
140

141 142
    var X = [],
        Y = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

    X[0] = 0;          Y[0] = 0;
    X[1] = stretch;    Y[1] = 0;
    X[2] = stretch;    Y[2] = 0.011*fontSize;
    X[3] = 0;          Y[3] = Y[2];
    X[4] = 0;          Y[4] = 0;

    var W = X[2],
        H = Y[2];

    return {XX: X, YY: Y, W: W, H: H};
}
CAccentLine.prototype.drawPath = function(pGraphics, XX, YY)
{
    pGraphics._m(XX[0], YY[0]);
    pGraphics._l(XX[1], YY[1]);
    pGraphics._l(XX[2], YY[2]);
    pGraphics._l(XX[3], YY[3]);
    pGraphics._l(XX[4], YY[4]);
}

Anna.Pavlova's avatar
Anna.Pavlova committed
164

Anna.Pavlova's avatar
Anna.Pavlova committed
165 166 167 168 169 170 171
function CAccentDoubleLine()
{
    CGlyphOperator.call(this);
}
extend(CAccentDoubleLine, CGlyphOperator);
CAccentDoubleLine.prototype.calcSize = function(stretch)
{
172
    var alpha = this.Parent.Get_CompiledCtrPrp().FontSize/36;
Anna.Pavlova's avatar
Anna.Pavlova committed
173 174 175 176 177 178 179 180 181 182

    var height = 2.843*alpha;
    var width  = 4.938*alpha;

    width = stretch > width ? stretch : width;

    return {width: width, height: height};
}
CAccentDoubleLine.prototype.calcCoord = function(stretch)
{
183
    var fontSize = this.Parent.Get_CompiledCtrPrp().FontSize;
Anna.Pavlova's avatar
Anna.Pavlova committed
184

185 186
    var X = [],
        Y = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

    X[0] = 0;          Y[0] = 0;
    X[1] = stretch;    Y[1] = 0;
    X[2] = stretch;    Y[2] = 0.011*fontSize;
    X[3] = 0;          Y[3] = Y[2];
    X[4] = 0;          Y[4] = 0;

    X[5] = 0;          Y[5] = 0.039486*fontSize;
    X[6] = stretch;    Y[6] = Y[5];
    X[7] = stretch;    Y[7] = 0.0503*fontSize;
    X[8] = 0;          Y[8] = Y[7];
    X[9] = 0;          Y[9] = Y[5];

    var W = X[7],
        H = Y[7];

    return {XX: X, YY: Y, W: W, H: H};
}
CAccentDoubleLine.prototype.drawPath = function(pGraphics, XX, YY)
{
    pGraphics._m(XX[0], YY[0]);
    pGraphics._l(XX[1], YY[1]);
    pGraphics._l(XX[2], YY[2]);
    pGraphics._l(XX[3], YY[3]);
    pGraphics._l(XX[4], YY[4]);
    pGraphics.df();

    pGraphics._s();
    pGraphics._m(XX[5], YY[5]);
    pGraphics._l(XX[6], YY[6]);
    pGraphics._l(XX[7], YY[7]);
    pGraphics._l(XX[8], YY[8]);
    pGraphics._l(XX[9], YY[9]);

}

223

Anna.Pavlova's avatar
Anna.Pavlova committed
224 225 226 227 228 229 230
function CAccentTilde()
{
    CGlyphOperator.call(this);
}
extend(CAccentTilde, CGlyphOperator);
CAccentTilde.prototype.calcSize = function(stretch)
{
231
    var betta = this.Parent.Get_CompiledCtrPrp().FontSize/36;
Anna.Pavlova's avatar
Anna.Pavlova committed
232 233 234 235 236 237 238 239

    var width = 9.047509765625*betta; // реальная на отрисовке width 7.495282031249999
    var height = 2.469444444444444*betta;

    return {width: width, height: height};
}
CAccentTilde.prototype.calcCoord = function(stretch)
{
240 241
    var X = [],
        Y = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

    X[0] = 0; Y[0] = 3066;
    X[1] = 2125; Y[1] = 7984;
    X[2] = 5624; Y[2] = 11256;
    X[3] = 9123; Y[3] = 14528;
    X[4] = 13913; Y[4] = 14528;
    X[5] = 18912; Y[5] = 14528;
    X[6] = 25827; Y[6] = 10144;
    X[7] = 32742; Y[7] = 5760;
    X[8] = 36324; Y[8] = 5760;
    X[9] = 39865; Y[9] = 5760;
    X[10] = 42239; Y[10] = 7641;
    X[11] = 44614; Y[11] = 9522;
    X[12] = 47030; Y[12] = 13492;
    X[13] = 50362; Y[13] = 11254;
    X[14] = 48571; Y[14] = 7544;
    X[15] = 44697; Y[15] = 3772;
    X[16] = 40823; Y[16] = 0;
    X[17] = 35283; Y[17] = 0;
    X[18] = 29951; Y[18] = 0;
    X[19] = 23098; Y[19] = 4384;
    X[20] = 16246; Y[20] = 8768;
    X[21] = 12622; Y[21] = 8768;
    X[22] = 9581; Y[22] = 8768;
    X[23] = 7290; Y[23] = 6845;
    X[24] = 4999; Y[24] = 4922;
    X[25] = 3249; Y[25] = 1243;
    X[26] = 0; Y[26] = 3066;


272 273
    var XX = [],
        YY = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
274

275
    var fontSize = this.Parent.Get_CompiledCtrPrp().FontSize;
Anna.Pavlova's avatar
Anna.Pavlova committed
276 277 278 279 280 281 282 283 284 285
    var textScale = fontSize/1000, // 1000 pt
        alpha = textScale*25.4/96 /64 ; // g_dKoef_px_to_mm = 25.4/96


    for(var i = 0; i < X.length; i++)
    {
        XX[i] = X[i]*alpha;
        YY[i] = (Y[5] - Y[i])*alpha*0.65; // сжали !
    }

286 287
    var W = XX[13],
        H = YY[5];
Anna.Pavlova's avatar
Anna.Pavlova committed
288

289
    return {XX: XX, YY: YY, W: W, H: H};
Anna.Pavlova's avatar
Anna.Pavlova committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
}
CAccentTilde.prototype.drawPath = function(pGraphics, XX, YY)
{
    pGraphics._m(XX[0], YY[0]);
    pGraphics._c(XX[0], YY[0], XX[1], YY[1], XX[2], YY[2] );
    pGraphics._c(XX[2], YY[2], XX[3], YY[3], XX[4], YY[4] );
    pGraphics._c(XX[4], YY[4], XX[5], YY[5], XX[6], YY[6] );
    pGraphics._c(XX[6], YY[6], XX[7], YY[7], XX[8], YY[8] );
    pGraphics._c(XX[8], YY[8], XX[9], YY[9], XX[10], YY[10] );
    pGraphics._c(XX[10], YY[10], XX[11], YY[11], XX[12], YY[12] );
    pGraphics._l(XX[13], YY[13]);
    pGraphics._c(XX[13], YY[13], XX[14], YY[14], XX[15], YY[15] );
    pGraphics._c(XX[15], YY[15], XX[16], YY[16], XX[17], YY[17] );
    pGraphics._c(XX[17], YY[17], XX[18], YY[18], XX[19], YY[19] );
    pGraphics._c(XX[19], YY[19], XX[20], YY[20], XX[21], YY[21] );
    pGraphics._c(XX[21], YY[21], XX[22], YY[22], XX[23], YY[23] );
    pGraphics._c(XX[23], YY[23], XX[24], YY[24], XX[25], YY[25] );
    pGraphics._l(XX[26], YY[26]);
}

Anna.Pavlova's avatar
Anna.Pavlova committed
310

Anna.Pavlova's avatar
Anna.Pavlova committed
311 312 313 314 315 316 317
function CAccentBreve()
{
    CGlyphOperator.call(this);
}
extend(CAccentBreve, CGlyphOperator);
CAccentBreve.prototype.calcSize = function(stretch)
{
318
    var betta = this.Parent.Get_CompiledCtrPrp().FontSize/36;
Anna.Pavlova's avatar
Anna.Pavlova committed
319 320 321 322 323 324 325 326

    var width =  4.2333333333333325*betta;
    var height = 2.469444444444445*betta;

    return {width: width, height: height};
}
CAccentBreve.prototype.calcCoord = function(stretch)
{
327 328
    var X = [],
        Y = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

    X[0] = 25161; Y[0] = 11372;
    X[1] = 24077; Y[1] = 5749;
    X[2] = 20932; Y[2] = 2875;
    X[3] = 17787; Y[3] = 0;
    X[4] = 12247; Y[4] = 0;
    X[5] = 7082; Y[5] = 0;
    X[6] = 4083; Y[6] = 2854;
    X[7] = 1083; Y[7] = 5707;
    X[8] = 0; Y[8] = 11372;
    X[9] = 3208; Y[9] = 12371;
    X[10] = 4249; Y[10] = 9623;
    X[11] = 5561; Y[11] = 8083;
    X[12] = 6873; Y[12] = 6542;
    X[13] = 8456; Y[13] = 5959;
    X[14] = 10039; Y[14] = 5376;
    X[15] = 12414; Y[15] = 5376;
    X[16] = 14746; Y[16] = 5376;
    X[17] = 16454; Y[17] = 5980;
    X[18] = 18162; Y[18] = 6583;
    X[19] = 19558; Y[19] = 8124;
    X[20] = 20953; Y[20] = 9665;
    X[21] = 21953; Y[21] = 12371;
    X[22] = 25161; Y[22] = 11372;


355 356
    var XX = [],
        YY = [];
Anna.Pavlova's avatar
Anna.Pavlova committed
357

358
    var fontSize = this.Parent.Get_CompiledCtrPrp().FontSize;
Anna.Pavlova's avatar
Anna.Pavlova committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
    var textScale = fontSize/1000, // 1000 pt
        alpha = textScale*25.4/96 /64 ; // g_dKoef_px_to_mm = 25.4/96

    for(var i = 0; i < X.length; i++)
    {
        XX[i] = X[i]*alpha ;
        YY[i] = Y[i]*alpha ;
    }

    var H = YY[9],
        W = XX[0];

    return {XX: XX, YY: YY, W: W, H: H};
}
CAccentBreve.prototype.drawPath = function(pGraphics, XX, YY)
{
    pGraphics._m(XX[0], YY[0]);
    pGraphics._c(XX[0], YY[0], XX[1], YY[1], XX[2], YY[2] );
    pGraphics._c(XX[2], YY[2], XX[3], YY[3], XX[4], YY[4] );
    pGraphics._c(XX[4], YY[4], XX[5], YY[5], XX[6], YY[6] );
    pGraphics._c(XX[6], YY[6], XX[7], YY[7], XX[8], YY[8] );
    pGraphics._l(XX[9], YY[9]);
    pGraphics._c(XX[9], YY[9], XX[10], YY[10], XX[11], YY[11] );
    pGraphics._c(XX[11], YY[11], XX[12], YY[12], XX[13], YY[13] );
    pGraphics._c(XX[13], YY[13], XX[14], YY[14], XX[15], YY[15] );
    pGraphics._c(XX[15], YY[15], XX[16], YY[16], XX[17], YY[17] );
    pGraphics._c(XX[17], YY[17], XX[18], YY[18], XX[19], YY[19] );
    pGraphics._c(XX[19], YY[19], XX[20], YY[20], XX[21], YY[21] );
    pGraphics._l(XX[22], YY[22]);
}

390 391
function CSign()
{
392
    this.sign = new CMathText(true);
393
    this.typeOper = null;
394
    this.Parent = null;
395
}
396
CSign.prototype.init = function(props)
397 398 399 400 401 402 403 404 405
{
    var bDot        = props.code === 0x307 || props.type === ACCENT_ONE_DOT,
        b2Dots      = props.code === 0x308 || props.type === ACCENT_TWO_DOTS,
        b3Dots      = props.code === 0x20DB || props.type === ACCENT_THREE_DOTS,
        bAccGrave   = props.code === 0x300 || props.type === ACCENT_GRAVE,
        bAccAcute   = props.code === 0x301 || props.type === ACCENT_ACUTE;

    if(bDot)
    {
406
        this.typeOper = ACCENT_ONE_DOT;
407 408 409 410
        this.sign.add(0x307);
    }
    else if(b2Dots)
    {
411
        this.typeOper = ACCENT_TWO_DOTS;
412 413 414 415
        this.sign.add(0x308);
    }
    else if(b3Dots)
    {
416
        this.typeOper = ACCENT_THREE_DOTS;
417 418 419 420
        this.sign.add(0x20DB);
    }
    else if(bAccGrave)
    {
421
        this.typeOper = ACCENT_GRAVE;
422 423 424 425
        this.sign.add(0x300);
    }
    else if(bAccAcute)
    {
426
        this.typeOper = ACCENT_ACUTE;
427 428 429 430
        this.sign.add(0x301);
    }
    else
    {
431
        this.typeOper = ACCENT_TEXT;
432
        this.sign.add(props.code);
433 434 435
    }
}
CSign.prototype.setPosition = function(pos)
436 437 438 439
{
    this.sign.setPosition(pos);
}
/*CSign.prototype.setPosition = function(pos)
440 441 442
{
    var shX = 0;

443
    if(this.typeOper == ACCENT_GRAVE)
444
        shX = 1.1*this.sign.size.widthG;
445
    else if(this.typeOper == ACCENT_ACUTE)
446
        shX = 1.25*this.sign.size.widthG;
447
    else if(this.typeOper == ACCENT_ONE_DOT)
448
        shX = 1.53*this.sign.size.widthG;
449
    else if(this.typeOper == ACCENT_TWO_DOTS)
450
        shX = 0.95*this.sign.size.widthG;
451
    else if(this.typeOper == ACCENT_THREE_DOTS)
452 453 454 455
        shX = 0.015*this.sign.size.widthG;
    
    var position =
    {
456
        x: pos.x + shX,
457 458 459
        y: pos.y + this.sign.size.ascent
    };
    this.sign.setPosition(position);
460
}*/
461 462
CSign.prototype.fixSize = function(oMeasure, stretch, bIncline)
{
463
    var ctrPrp = this.Parent.Get_CompiledCtrPrp();
464

Anna.Pavlova's avatar
Anna.Pavlova committed
465
    var rPrp = new CTextPr();
466
    var defaultRPrp = this.Parent.ParaMath.Get_Default_TPrp();
467
    rPrp.Merge(defaultRPrp);
468
    rPrp.Merge(ctrPrp);
469 470
    rPrp.Italic = false; // не меняем значок
    rPrp.Bold = false;
471 472 473

    oMeasure.SetFont(rPrp);

474
    this.sign.Resize(oMeasure);
475

Anna.Pavlova's avatar
Anna.Pavlova committed
476 477 478 479
    /*if(this.typeOper == ACCENT_THREE_DOTS)
     this.dH = 1.2*ctrPrp.FontSize/36;
     else
     this.dH = 1.2*ctrPrp.FontSize/36;*/
480

Anna.Pavlova's avatar
Anna.Pavlova committed
481 482
    //var height = this.sign.size.height + this.dH,
    var height = this.sign.size.height,
483 484 485 486 487 488 489
        width = this.sign.size.widthG;

    if(bIncline)
        width += 0.1 * this.sign.size.height; // incline

    this.size = {width: width, height: height};
}
490
CSign.prototype.draw = function(x, y, pGraphics)
491
{
492
    this.sign.draw(x, y, pGraphics);
493
}
494
CSign.prototype.relate = function(parent)
495
{
496
    this.Parent = parent;
497
}
498
CSign.prototype.getCodeCharacter = function()
499 500 501
{
    return this.sign.value;
}
Anna.Pavlova's avatar
Anna.Pavlova committed
502

503
function CAccent(props)
504
{
505
	this.Id = g_oIdCounter.Get_NewId();
Anna.Pavlova's avatar
Anna.Pavlova committed
506 507
    this.kind = MATH_ACCENT;

508 509 510 511 512 513 514
    //// Properties
    this.Pr =
    {
        chr:        null,
        chrType:    null
    };

515 516
    this.shiftX   = 0;
    this.shiftX_2 = 0;
517 518
    this.gap = 0;

519
    /////////////////
520

521
    this.operator = new COperator(OPER_ACCENT);
522

523 524
    CAccent.superclass.constructor.call(this);
    //CMathBase.call(this);
525

526 527
    if(props !== null && typeof(props) !== "undefined")
        this.init(props);
528

529
	g_oTableId.Add( this, this.Id );	
Anna.Pavlova's avatar
Anna.Pavlova committed
530
}
Anna.Pavlova's avatar
Anna.Pavlova committed
531
extend(CAccent, CMathBase);
Anna.Pavlova's avatar
Anna.Pavlova committed
532 533
CAccent.prototype.init = function(props)
{
534
    this.setProperties(props);
Anna.Pavlova's avatar
Anna.Pavlova committed
535 536 537 538 539

    this.setDimension(1, 1);
    this.setContent();

    this.elements[0][0].SetDot(true);
540 541 542
}
CAccent.prototype.setChr = function(chr)
{
543 544
    this.Pr.chr = chr;
    this.Pr.chrType = null;
545 546 547 548
    this.RecalcInfo.bProps = true;
}
CAccent.prototype.setChrType = function(chrType)
{
549 550
    this.Pr.chr = null;
    this.Pr.chrType = chrType;
551
    this.RecalcInfo.bProps = true;
Anna.Pavlova's avatar
Anna.Pavlova committed
552
}
553 554 555 556
CAccent.prototype.IsAccent = function()
{
    return true;
}
Anna.Pavlova's avatar
Anna.Pavlova committed
557
CAccent.prototype.old_init = function(properties)
558 559 560 561 562 563 564 565
{
    var type = properties.chrType,
        code;

    var typeOper, codeChr;
    var operator;

    ////    ВРЕМЕННО !!!!
566

567 568 569
    var bCode = false,
        bType = typeof(type) !== "undefined" && type !== null;

570
    if(typeof(properties.chr) === "string")
571 572
    {
        bCode = true;
573
        code = properties.chr.charCodeAt(0);
574
    }
575 576 577 578 579 580 581 582 583 584 585

    /*var bDot        = code === 0x307 || props.chr.type === ACCENT_ONE_DOT,
        b2Dots      = code === 0x308 || props.chr.type === ACCENT_TWO_DOTS,
        b3Dots      = code === 0x20DB || props.chr.type === ACCENT_THREE_DOTS,
        bAccGrave   = code === 0x300 || props.chr.type === ACCENT_GRAVE,
        bAccAcute   = code === 0x301 || props.chr.type === ACCENT_ACUTE;

    if(bDot || b2Dots || b3Dots || bAccGrave || bAccAcute)
    {
        this.accent = new CMathText();
        this.accent.add(code);
586
        typeOper = props.chr.type;
587
    }*/
588

589
    if(code === 0x302 || type === ACCENT_CIRCUMFLEX)
590
    {
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
        typeOper = ACCENT_CIRCUMFLEX;
        codeChr = 0x302;

        operator = new CCircumflex();
        var props =
        {
            turn:   TURN_MIRROR_0
        };
        operator.init(props);
    }
    else if(code === 0x30C || type === ACCENT_COMB_CARON)
    {
        typeOper = ACCENT_COMB_CARON;
        codeChr = 0x30C;

        operator = new CCircumflex();
        var props =
        {
            turn:   TURN_0
        };
        operator.init(props);
    }
    else if(code === 0x305 || type === ACCENT_LINE)
    {
        typeOper = ACCENT_LINE;
        //codeChr = 0x332;
        codeChr = 0x305;

        operator = new CLine();
    }
    else if(code === 0x33F || type === ACCENT_DOUBLE_LINE)
    {
        typeOper = ACCENT_DOUBLE_LINE;
        //codeChr = 0x333;
        codeChr = 0x33F;

        operator = new CDoubleLine();
    }
    else if(code === 0x303 || type === ACCENT_TILDE)
    {
        typeOper = ACCENT_TILDE;
        codeChr = 0x303;

        operator = new CTilde();
    }
    else if(code === 0x306 || type === ACCENT_BREVE)
    {
        typeOper = ACCENT_BREVE;
        codeChr = 0x306;

        operator = new CBreve();
        var props =
        {
            turn:   TURN_MIRROR_0
        };
        operator.init(props);
    }
    else if(code == 0x311 || type == ACCENT_INVERT_BREVE)
    {
        typeOper = ACCENT_INVERT_BREVE;
        codeChr = 0x311;

        operator = new CBreve();
        var props =
        {
            turn:   TURN_0
        };
        operator.init(props);
    }
    else if(code === 0x20D6 || type === ACCENT_ARROW_LEFT)
    {

        typeOper = ACCENT_ARROW_LEFT;
        codeChr = 0x20D6;

        /*var glyph = new CCombiningArrow();
        var props =
        {
            location:   LOCATION_TOP,
            turn:       TURN_0
        };
        glyph.init(props);*/

        operator = new COperator(OPER_ACCENT);

        var props =
        {
            type:   properties.chrType,
            chr:    properties.chr
        };

        var defaultProps =
        {
            loc:   LOCATION_TOP
        };

        operator.init(props, defaultProps);
    }
    else if(code === 0x20D7 || type === ACCENT_ARROW_RIGHT)
    {
        typeOper = ACCENT_ARROW_RIGHT;
        codeChr = 0x20D7;

        /*var glyph = new CCombiningArrow();
        var props =
        {
            location:   LOCATION_TOP,
            turn:       TURN_180
        };
        glyph.init(props);

        operator = new COperator(glyph);*/

        operator = new COperator(OPER_ACCENT);

        var props =
        {
            type:   properties.chrType,
            chr:    properties.chr
        };

        var defaultProps =
        {
            loc:   LOCATION_TOP
        };

        operator.init(props, defaultProps);
    }
    else if(code === 0x20E1 || type === ACCENT_ARROW_LR)
    {
        typeOper = ACCENT_ARROW_LR;
        codeChr = 0x20E1;

        /*var glyph = new CCombining_LR_Arrow();
        var props =
        {
            location:   LOCATION_TOP,
            turn:       TURN_0
        };

        glyph.init(props);

        operator = new COperator(glyph);*/

        operator = new COperator(OPER_ACCENT);

        var props =
        {
            type:   properties.chrType,
            chr:    properties.chr
        };

        var defaultProps =
        {
            loc:   LOCATION_TOP
        };

        operator.init(props, defaultProps);
    }
    else if(code === 0x20D0 || type === ACCENT_HALF_ARROW_LEFT)
    {
        typeOper = ACCENT_HALF_ARROW_LEFT;
        codeChr = 0x20D0;

        /*var glyph = new CCombiningHalfArrow();
        var props =
        {
            location:   LOCATION_TOP,
            turn:       TURN_0
        };
        glyph.init(props);

        operator = new COperator(glyph);*/

        operator = new COperator(OPER_ACCENT);

        var props =
        {
            type:   properties.chrType,
            chr:    properties.chr
        };

        var defaultProps =
        {
            loc:   LOCATION_TOP
        };

        operator.init(props, defaultProps);
    }
    else if(code === 0x20D1 || type ===  ACCENT_HALF_ARROW_RIGHT)
    {
        typeOper = ACCENT_HALF_ARROW_RIGHT;
        codeChr = 0x20D1;

        /*var glyph = new CCombiningHalfArrow();
        var props =
        {
            location:   LOCATION_TOP,
            turn:       TURN_180
        };
        glyph.init(props);

        operator = new COperator(glyph);*/

        operator = new COperator(OPER_ACCENT);

        var props =
        {
            type:   properties.chrType,
            chr:    properties.chr
        };

        var defaultProps =
        {
            loc:   LOCATION_TOP
        };

        operator.init(props, defaultProps);

    }
    /*if(code === 0x302 || type === ACCENT_CIRCUMFLEX)
    {
        typeOper = ACCENT_CIRCUMFLEX;
814
        this.code = 0x302;
Anna.Pavlova's avatar
Anna.Pavlova committed
815

816 817 818
        accent = new CCircumflex();
        accent.setTurn(TURN_0);
    }
819
    else if(code === 0x30C || type === ACCENT_COMB_CARON)
820
    {
821
        typeOper = ACCENT_COMB_CARON;
822
        this.code = 0x30C;
Anna.Pavlova's avatar
Anna.Pavlova committed
823

824 825 826
        accent = new CCircumflex();
        accent.setTurn(TURN_MIRROR_0);
    }
827
    else if(code === 0x332 || type === ACCENT_LINE)
828
    {
829
        typeOper = ACCENT_LINE;
830
        this.code = 0x332;
Anna.Pavlova's avatar
Anna.Pavlova committed
831

832 833
        accent = new CLine();
    }
834
    else if(code === 0x333 || type === ACCENT_DOUBLE_LINE)
835
    {
836
        typeOper = ACCENT_DOUBLE_LINE;
837
        this.code = 0x333;
Anna.Pavlova's avatar
Anna.Pavlova committed
838

Anna.Pavlova's avatar
Anna.Pavlova committed
839
        accent = new CDoubleLine();
840
    }
841
    else if(code === 0x303 || type === ACCENT_TILDE)
842
    {
843
        typeOper = ACCENT_TILDE;
844
        this.code = 0x303;
Anna.Pavlova's avatar
Anna.Pavlova committed
845

846 847
        accent = new CTilde();
    }
848
    else if(code === 0x306 || type === ACCENT_BREVE)
849
    {
850
        typeOper = ACCENT_BREVE;
851
        this.code = 0x306;
Anna.Pavlova's avatar
Anna.Pavlova committed
852

853 854 855
        accent = new CBreve();
        accent.setTurn(TURN_MIRROR_0);
    }
856
    else if(code == 0x311 || type == ACCENT_INVERT_BREVE)
857
    {
858
        typeOper = ACCENT_INVERT_BREVE;
859
        this.code = 0x311;
Anna.Pavlova's avatar
Anna.Pavlova committed
860

861 862 863
        accent = new CBreve();
        accent.setTurn(TURN_0);
    }
864 865
    else if(code === 0x20D6 || type === ACCENT_ARROW_LEFT)
    {
866
        typeOper = ACCENT_ARROW_LEFT;
867
        this.code = 0x20D6;
Anna.Pavlova's avatar
Anna.Pavlova committed
868

869
        glyph = new CCombiningArrow();
870
        var prp =
871 872 873 874
        {
            location:   LOCATION_TOP,
            turn:       TURN_0
        };
875
        glyph.init(prp);
876 877 878 879
        accent = new COperator(glyph);
    }
    else if(code === 0x20D7 || type === ACCENT_ARROW_RIGHT)
    {
880
        typeOper = ACCENT_ARROW_RIGHT;
881
        this.code = 0x20D7;
Anna.Pavlova's avatar
Anna.Pavlova committed
882

883
        glyph = new CCombiningArrow();
884
        var prp =
885 886 887 888
        {
            location:   LOCATION_TOP,
            turn:       TURN_180
        };
889
        glyph.init(prp);
890 891 892 893
        accent = new COperator(glyph);
    }
    else if(code === 0x20E1 || type === ACCENT_ARROW_LR)
    {
894
        typeOper = ACCENT_ARROW_LR;
895
        this.code = 0x20E1;
Anna.Pavlova's avatar
Anna.Pavlova committed
896

897
        glyph = new CCombining_LR_Arrow();
898
        var prp =
899 900 901 902
        {
            location:   LOCATION_TOP,
            turn:       TURN_0
        };
903
        glyph.init(prp);
904 905 906 907
        accent = new COperator(glyph);
    }
    else if(code === 0x20D0 || type === ACCENT_HALF_ARROW_LEFT)
    {
908
        typeOper = ACCENT_HALF_ARROW_LEFT;
909
        this.code = 0x20D0;
Anna.Pavlova's avatar
Anna.Pavlova committed
910

911
        glyph = new CCombiningHalfArrow();
912
        var prp =
913 914 915 916
        {
            location:   LOCATION_TOP,
            turn:       TURN_0
        };
917
        glyph.init(prp);
918 919 920 921
        accent = new COperator(glyph);
    }
    else if(code === 0x20D1 || type ===  ACCENT_HALF_ARROW_RIGHT)
    {
922
        typeOper = ACCENT_HALF_ARROW_RIGHT;
923
        this.code = 0x20D1;
Anna.Pavlova's avatar
Anna.Pavlova committed
924

925
        glyph = new CCombiningHalfArrow();
926
        var prp =
927 928 929 930
        {
            location:   LOCATION_TOP,
            turn:       TURN_180
        };
931
        glyph.init(prp);
932
        accent = new COperator(glyph);
933
    }*/
934
    ///// group characters /////
935
    /*else if(code === 0x2190 || type === ARROW_LEFT)
936
    {
937 938
        typeOper = ARROW_LEFT;
        codeChr = 0x2190;
Anna.Pavlova's avatar
Anna.Pavlova committed
939

940
        operator = new CSingleArrow();
941

942
        var props =
943 944 945 946
        {
            location:   this.loc,
            turn:       TURN_0
        };
947
        operator.init(props);
948 949 950
    }
    else if(code === 0x2192 || type === ARROW_RIGHT)
    {
951 952
        typeOper = ARROW_RIGHT;
        codeChr = 0x2192;
Anna.Pavlova's avatar
Anna.Pavlova committed
953

954
        glyph = new CSingleArrow();
955
        var prp =
956 957 958 959
        {
            location:   this.loc,
            turn:       TURN_180
        };
960
        glyph.init(prp);
961 962 963
    }
    else if(code === 0x2194 || type === ARROW_LR)
    {
964 965
        typeOper = ARROW_LR;
        codeChr = 0x2194;
Anna.Pavlova's avatar
Anna.Pavlova committed
966

967
        glyph = new CLeftRightArrow();
968
        var prp =
969 970 971 972
        {
            location:   this.loc,
            turn:       TURN_0
        };
973
        glyph.init(prp);
974 975 976
    }
    else if(code === 0x21D0 || type === DOUBLE_LEFT_ARROW)
    {
977 978
        typeOper = DOUBLE_LEFT_ARROW;
        codeChr = 0x21D0;
Anna.Pavlova's avatar
Anna.Pavlova committed
979

980
        glyph = new CDoubleArrow();
981
        var prp =
982 983 984 985
        {
            location:   this.loc,
            turn:       TURN_0
        };
986
        glyph.init(prp);
987 988 989
    }
    else if(code === 0x21D2 || type === DOUBLE_RIGHT_ARROW)
    {
990 991
        typeOper = DOUBLE_RIGHT_ARROW;
        codeChr = 0x21D2;
Anna.Pavlova's avatar
Anna.Pavlova committed
992

993
        glyph = new CDoubleArrow();
994
        var prp =
995 996 997 998
        {
            location:   this.loc,
            turn:       TURN_180
        };
999
        glyph.init(prp);
1000 1001 1002
    }
    else if(code === 0x21D4 || type === DOUBLE_ARROW_LR)
    {
1003 1004
        typeOper = DOUBLE_ARROW_LR;
        codeChr = 0x21D4;
Anna.Pavlova's avatar
Anna.Pavlova committed
1005

1006
        glyph = new CLR_DoubleArrow();
1007
        var prp =
1008 1009 1010 1011
        {
            location:   this.loc,
            turn:       TURN_0
        };
1012
        glyph.init(prp);
1013
    }*/
1014
    /////
1015
    else if(bCode || bType)
1016
    {
1017
        typeOper = ACCENT_SIGN;
1018

1019 1020
        operator = new CSign();
        var props =
1021
        {
1022
            type:   type,
1023 1024
            code:   code
        };
1025 1026
        operator.init(props);
        codeChr = operator.getCodeCharacter();
1027
    }
1028 1029
    else
    {
1030 1031
        /*typeOper = ACCENT_COMB_CARON;
        codeChr = 0x30C;
1032

1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
        operator = new CCircumflex();
        var props =
        {
            turn:   TURN_MIRROR_0
        };
        operator.init(props);*/

        typeOper = ACCENT_CIRCUMFLEX;
        codeChr = 0x302;

        operator = new CCircumflex();
        var props =
        {
            turn:   TURN_MIRROR_0
        };
        operator.init(props);
1049
    }
1050

1051 1052
    this.operator = operator;
    this.operator.relate(this);
1053 1054 1055 1056 1057

    ////
    // TO DO
    // убрать
    //
1058 1059 1060
    this.typeOper = typeOper;
    this.code = codeChr;

1061 1062
    ////

1063 1064 1065 1066
    this.setDimension(1, 1);
    this.setContent();

    //this.setOperator(accent);
Anna.Pavlova's avatar
Anna.Pavlova committed
1067
    this.elements[0][0].SetDot(true);
1068 1069 1070 1071

}
CAccent.prototype.setPosition = function(pos)
{
1072 1073
    this.pos.x = pos.x;
    this.pos.y = pos.y - this.size.ascent;
1074

1075 1076 1077 1078
    var width = this.size.width - this.GapLeft - this.GapRight;

    var alignOp  =  (width - this.operator.size.width)/2,
        alignCnt =  (width- this.elements[0][0].size.width)/2;
1079

1080 1081
    var PosOper = new CMathPosition();

1082
    PosOper.x = this.pos.x + this.GapLeft  + alignOp;
1083

1084
    PosOper.y = this.pos.y + this.shiftX_2 ;
1085
    //PosOper.y = this.pos.y + this.size.ascent - this.shiftX;
1086 1087


1088 1089 1090
    this.operator.setPosition(PosOper);

    var PosBase = new CMathPosition();
1091

1092
    PosBase.x = this.pos.x + this.GapLeft + alignCnt;
1093
    PosBase.y = this.pos.y + this.operator.size.height + this.gap;
1094

1095
    this.elements[0][0].setPosition(PosBase);
Anna.Pavlova's avatar
Anna.Pavlova committed
1096
}
1097
CAccent.prototype.getPropsForWrite = function()
Anna.Pavlova's avatar
Anna.Pavlova committed
1098
{
1099
    return this.Pr;
Anna.Pavlova's avatar
Anna.Pavlova committed
1100
}
1101
CAccent.prototype.Resize = function(oMeasure, Parent, ParaMath, RPI, ArgSize)
Anna.Pavlova's avatar
Anna.Pavlova committed
1102
{
1103 1104 1105
    this.Parent = Parent;
    this.ParaMath = ParaMath;

1106 1107 1108 1109
    if(this.RecalcInfo.bProps == true)
    {
        var prp =
        {
1110 1111
            type:   this.Pr.chrType,
            chr:    this.Pr.chr,
1112 1113 1114 1115 1116 1117 1118 1119
            loc:    LOCATION_TOP
        };

        var defaultPrp =
        {
            type:   ACCENT_CIRCUMFLEX
        };

1120
        this.operator.mergeProperties(prp, defaultPrp);
1121 1122
    }

1123 1124
    this.operator.relate(this);

Anna.Pavlova's avatar
Anna.Pavlova committed
1125
    var base = this.elements[0][0];
1126
    base.Resize(oMeasure, this, ParaMath, RPI, ArgSize);
Anna.Pavlova's avatar
Anna.Pavlova committed
1127

1128 1129 1130 1131
    var ctrPrp = this.Get_CompiledCtrPrp();
    oMeasure.SetFont(ctrPrp);

    this.operator.fixSize(ParaMath, oMeasure, base.size.width);
Anna.Pavlova's avatar
Anna.Pavlova committed
1132

1133 1134 1135 1136 1137

    if(this.operator.typeOper == OPERATOR_TEXT)
    {
        var letterX = new CMathText(true);
        letterX.add(0x78);
1138
        letterX.Resize(oMeasure, null);
1139 1140
        this.gap = this.operator.size.ascentSign - letterX.size.ascent;

1141 1142
        //this.shiftX_2 = this.operator.size.ascentSign;
        this.shiftX_2 = 0;
1143 1144
    }

Anna.Pavlova's avatar
Anna.Pavlova committed
1145 1146

    var width  = base.size.width > this.operator.size.width ? base.size.width : this.operator.size.width,
1147 1148
        height = base.size.height + this.operator.size.height + this.gap,
        ascent = this.operator.size.height + this.gap + this.elements[0][0].size.ascent;
Anna.Pavlova's avatar
Anna.Pavlova committed
1149

1150

Anna.Pavlova's avatar
Anna.Pavlova committed
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
    this.size = {height: height, width: width, ascent: ascent};
}
CAccent.prototype.getBase = function()
{
    return this.elements[0][0];
}
CAccent.prototype.draw = function(x, y, pGraphics)
{
    this.elements[0][0].draw(x, y, pGraphics);

1161 1162
    var MergedCtrPrp = this.Get_CompiledCtrPrp();
    var FontSize = MergedCtrPrp.FontSize,
Anna.Pavlova's avatar
Anna.Pavlova committed
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
        FontFamily = {Name: "Cambria Math", Index: -1};

    var obj = {FontSize: FontSize, FontFamily: FontFamily};

    var accFont = new CTextPr();
    accFont.Set_FromObject(obj);


    pGraphics.SetFont(accFont);
    pGraphics.p_color(0,0,0, 255);
    pGraphics.b_color1(0,0,0, 255);

    this.operator.draw(x, y, pGraphics);
}
1177 1178
CAccent.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
1179
    var align =  (this.size.width - this.elements[0][0].size.width - this.GapLeft - this.GapRight)/2;
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194

    SearchPos.CurX += this.GapLeft + align;

    var result =  this.elements[0][0].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);

    if(result)
    {
        SearchPos.Pos.Update(0, Depth);
        SearchPos.Pos.Update(0, Depth+1);
    }

    SearchPos.CurX += this.GapRight + align;

    return result;
}
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
CAccent.prototype.setProperties = function(props)
{
    this.Pr.chr     = props.chr;
    this.Pr.chrType = props.chrType;

    this.setCtrPrp(props.ctrPrp);

    this.RecalcInfo.bProps = true;
}
CAccent.prototype.fillMathComposition = function(props, contents /*array*/)
{
    this.init(props);

    // Base
    this.elements[0][0] = contents[0];
}
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
CAccent.prototype.Save_Changes = function(Data, Writer)
{
	Writer.WriteLong( historyitem_type_acc );
}
CAccent.prototype.Load_Changes = function(Reader)
{
}
CAccent.prototype.Refresh_RecalcData = function(Data)
{
}
CAccent.prototype.Write_ToBinary2 = function( Writer )
{
	Writer.WriteLong( historyitem_type_acc );
1224
	Writer.WriteString2( this.getBase().Id );
1225 1226 1227 1228 1229 1230
	
	this.CtrPrp.Write_ToBinary(Writer);
	
	var StartPos = Writer.GetCurPosition();
    Writer.Skip(4);
    var Flags = 0;
1231
	if ( undefined != this.Pr.chr )
1232
    {
1233
		Writer.WriteLong(this.Pr.chr);	
1234 1235 1236 1237 1238 1239
		Flags |= 1;
	}
	var EndPos = Writer.GetCurPosition();
    Writer.Seek( StartPos );
    Writer.WriteLong( Flags );
    Writer.Seek( EndPos );
1240 1241 1242
}
CAccent.prototype.Read_FromBinary2 = function( Reader )
{
1243 1244 1245 1246
	var props = {ctrPrp: new CTextPr()};
	var arrElems = [];
	
	arrElems.push(g_oTableId.Get_ById( Reader.GetString2()));
1247

1248
	props.ctrPrp.Read_FromBinary(Reader);
1249 1250 1251
	
	var Flags = Reader.GetLong();
	if ( Flags & 1 )
1252
		props.chr = Reader.GetLong();	
1253 1254
		
	this.fillMathComposition (props, arrElems);
1255
}