PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/source/generic/gen.cxx

https://bitbucket.org/mst/ooo340
C++ | 661 lines | 484 code | 77 blank | 100 comment | 81 complexity | 7e7c7cbf021166dc3e7e834cc7f473b0 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * Copyright 2000, 2010 Oracle and/or its affiliates.
  6. *
  7. * OpenOffice.org - a multi-platform office productivity suite
  8. *
  9. * This file is part of OpenOffice.org.
  10. *
  11. * OpenOffice.org is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License version 3
  13. * only, as published by the Free Software Foundation.
  14. *
  15. * OpenOffice.org is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License version 3 for more details
  19. * (a copy is included in the LICENSE file that accompanied this code).
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * version 3 along with OpenOffice.org. If not, see
  23. * <http://www.openoffice.org/license.html>
  24. * for a copy of the LGPLv3 License.
  25. *
  26. ************************************************************************/
  27. // MARKER(update_precomp.py): autogen include statement, do not remove
  28. #include "precompiled_tools.hxx"
  29. #include <tools/debug.hxx>
  30. #include <tools/gen.hxx>
  31. #include <tools/stream.hxx>
  32. // =======================================================================
  33. SvStream& operator>>( SvStream& rIStream, Pair& rPair )
  34. {
  35. DBG_ASSERTWARNING( rIStream.GetVersion(), "Pair::>> - Solar-Version not set on rIStream" );
  36. if ( rIStream.GetCompressMode() == COMPRESSMODE_FULL )
  37. {
  38. unsigned char cId;
  39. unsigned char cAry[8];
  40. int i;
  41. int i1;
  42. int i2;
  43. UINT32 nNum;
  44. rIStream >> cId;
  45. i1 = (cId & 0x70) >> 4;
  46. i2 = cId & 0x07;
  47. rIStream.Read( cAry, i1+i2 );
  48. nNum = 0;
  49. i = i1;
  50. while ( i )
  51. {
  52. i--;
  53. nNum <<= 8;
  54. nNum |= cAry[i];
  55. }
  56. if ( cId & 0x80 )
  57. nNum ^= 0xFFFFFFFF;
  58. rPair.nA = (INT32)nNum;
  59. nNum = 0;
  60. i = i1+i2;
  61. while ( i > i1 )
  62. {
  63. i--;
  64. nNum <<= 8;
  65. nNum |= cAry[i];
  66. }
  67. if ( cId & 0x08 )
  68. nNum ^= 0xFFFFFFFF;
  69. rPair.nB = (INT32)nNum;
  70. }
  71. else
  72. {
  73. rIStream >> rPair.nA >> rPair.nB;
  74. }
  75. return rIStream;
  76. }
  77. // -----------------------------------------------------------------------
  78. SvStream& operator<<( SvStream& rOStream, const Pair& rPair )
  79. {
  80. DBG_ASSERTWARNING( rOStream.GetVersion(), "Pair::<< - Solar-Version not set on rOStream" );
  81. if ( rOStream.GetCompressMode() == COMPRESSMODE_FULL )
  82. {
  83. unsigned char cAry[9];
  84. int i = 1;
  85. UINT32 nNum;
  86. cAry[0] = 0;
  87. nNum = (UINT32)(INT32)rPair.nA;
  88. if ( rPair.nA < 0 )
  89. {
  90. cAry[0] |= 0x80;
  91. nNum ^= 0xFFFFFFFF;
  92. }
  93. if ( nNum )
  94. {
  95. cAry[i] = (unsigned char)(nNum & 0xFF);
  96. nNum >>= 8;
  97. i++;
  98. if ( nNum )
  99. {
  100. cAry[i] = (unsigned char)(nNum & 0xFF);
  101. nNum >>= 8;
  102. i++;
  103. if ( nNum )
  104. {
  105. cAry[i] = (unsigned char)(nNum & 0xFF);
  106. nNum >>= 8;
  107. i++;
  108. if ( nNum )
  109. {
  110. cAry[i] = (unsigned char)(nNum & 0xFF);
  111. nNum >>= 8;
  112. i++;
  113. cAry[0] |= 0x40;
  114. }
  115. else
  116. cAry[0] |= 0x30;
  117. }
  118. else
  119. cAry[0] |= 0x20;
  120. }
  121. else
  122. cAry[0] |= 0x10;
  123. }
  124. nNum = (UINT32)(INT32)rPair.nB;
  125. if ( rPair.nB < 0 )
  126. {
  127. cAry[0] |= 0x08;
  128. nNum ^= 0xFFFFFFFF;
  129. }
  130. if ( nNum )
  131. {
  132. cAry[i] = (unsigned char)(nNum & 0xFF);
  133. nNum >>= 8;
  134. i++;
  135. if ( nNum )
  136. {
  137. cAry[i] = (unsigned char)(nNum & 0xFF);
  138. nNum >>= 8;
  139. i++;
  140. if ( nNum )
  141. {
  142. cAry[i] = (unsigned char)(nNum & 0xFF);
  143. nNum >>= 8;
  144. i++;
  145. if ( nNum )
  146. {
  147. cAry[i] = (unsigned char)(nNum & 0xFF);
  148. nNum >>= 8;
  149. i++;
  150. cAry[0] |= 0x04;
  151. }
  152. else
  153. cAry[0] |= 0x03;
  154. }
  155. else
  156. cAry[0] |= 0x02;
  157. }
  158. else
  159. cAry[0] |= 0x01;
  160. }
  161. rOStream.Write( cAry, i );
  162. }
  163. else
  164. {
  165. rOStream << rPair.nA << rPair.nB;
  166. }
  167. return rOStream;
  168. }
  169. /*************************************************************************
  170. |*
  171. |* Rectangle::SetSize()
  172. |*
  173. |* Beschreibung GEN.SDW
  174. |* Ersterstellung DV 29.10.91
  175. |* Letzte Aenderung MM 21.04.94
  176. |*
  177. *************************************************************************/
  178. void Rectangle::SetSize( const Size& rSize )
  179. {
  180. if ( rSize.Width() < 0 )
  181. nRight = nLeft + rSize.Width() +1;
  182. else if ( rSize.Width() > 0 )
  183. nRight = nLeft + rSize.Width() -1;
  184. else
  185. nRight = RECT_EMPTY;
  186. if ( rSize.Height() < 0 )
  187. nBottom = nTop + rSize.Height() +1;
  188. else if ( rSize.Height() > 0 )
  189. nBottom = nTop + rSize.Height() -1;
  190. else
  191. nBottom = RECT_EMPTY;
  192. }
  193. /*************************************************************************
  194. |*
  195. |* Rectangle::Union()
  196. |*
  197. |* Beschreibung GEN.SDW
  198. |* Ersterstellung TH 20.10.92
  199. |* Letzte Aenderung MM 21.04.94
  200. |*
  201. *************************************************************************/
  202. Rectangle& Rectangle::Union( const Rectangle& rRect )
  203. {
  204. if ( rRect.IsEmpty() )
  205. return *this;
  206. if ( IsEmpty() )
  207. *this = rRect;
  208. else
  209. {
  210. nLeft = Min( Min( nLeft, rRect.nLeft ), Min( nRight, rRect.nRight ) );
  211. nRight = Max( Max( nLeft, rRect.nLeft ), Max( nRight, rRect.nRight ) );
  212. nTop = Min( Min( nTop, rRect.nTop ), Min( nBottom, rRect.nBottom ) );
  213. nBottom = Max( Max( nTop, rRect.nTop ), Max( nBottom, rRect.nBottom ) );
  214. }
  215. return *this;
  216. }
  217. /*************************************************************************
  218. |*
  219. |* Rectangle::Intersection()
  220. |*
  221. |* Beschreibung GEN.SDW
  222. |* Ersterstellung TH 20.10.92
  223. |* Letzte Aenderung MM 21.04.94
  224. |*
  225. *************************************************************************/
  226. Rectangle& Rectangle::Intersection( const Rectangle& rRect )
  227. {
  228. if ( IsEmpty() )
  229. return *this;
  230. if ( rRect.IsEmpty() )
  231. {
  232. *this = Rectangle();
  233. return *this;
  234. }
  235. // nicht mit umgedrehten Rechtecken arbeiten
  236. Rectangle aTmpRect( rRect );
  237. Justify();
  238. aTmpRect.Justify();
  239. // Schnitt bilden
  240. nLeft = Max( nLeft, aTmpRect.nLeft );
  241. nRight = Min( nRight, aTmpRect.nRight );
  242. nTop = Max( nTop, aTmpRect.nTop );
  243. nBottom= Min( nBottom, aTmpRect.nBottom );
  244. // Feststellen ob Schnitt leer
  245. if ( nRight < nLeft || nBottom < nTop )
  246. *this = Rectangle();
  247. return *this;
  248. }
  249. /*************************************************************************
  250. |*
  251. |* Rectangle::Justify()
  252. |*
  253. |* Beschreibung GEN.SDW
  254. |* Ersterstellung DV 07.03.91
  255. |* Letzte Aenderung DV 07.03.91
  256. |*
  257. *************************************************************************/
  258. void Rectangle::Justify()
  259. {
  260. long nHelp;
  261. // Abfrage, ob Right kleiner Left
  262. if ( (nRight < nLeft) && (nRight != RECT_EMPTY) )
  263. {
  264. nHelp = nLeft;
  265. nLeft = nRight;
  266. nRight = nHelp;
  267. }
  268. // Abfrage, ob Bottom kleiner Top
  269. if ( (nBottom < nTop) && (nBottom != RECT_EMPTY) )
  270. {
  271. nHelp = nBottom;
  272. nBottom = nTop;
  273. nTop = nHelp;
  274. }
  275. }
  276. /*************************************************************************
  277. |*
  278. |* Rectangle::IsInside()
  279. |*
  280. |* Beschreibung GEN.SDW
  281. |* Ersterstellung TH 19.03.90
  282. |* Letzte Aenderung MM 21.04.94
  283. |*
  284. *************************************************************************/
  285. BOOL Rectangle::IsInside( const Point& rPoint ) const
  286. {
  287. if ( IsEmpty() )
  288. return FALSE;
  289. BOOL bRet = TRUE;
  290. if ( nLeft <= nRight )
  291. {
  292. if ( (rPoint.X() < nLeft) || (rPoint.X() > nRight) )
  293. bRet = FALSE;
  294. }
  295. else
  296. {
  297. if ( (rPoint.X() > nLeft) || (rPoint.X() < nRight) )
  298. bRet = FALSE;
  299. }
  300. if ( nTop <= nBottom )
  301. {
  302. if ( (rPoint.Y() < nTop) || (rPoint.Y() > nBottom) )
  303. bRet = FALSE;
  304. }
  305. else
  306. {
  307. if ( (rPoint.Y() > nTop) || (rPoint.Y() < nBottom) )
  308. bRet = FALSE;
  309. }
  310. return bRet;
  311. }
  312. /*************************************************************************
  313. |*
  314. |* Rectangle::IsInside()
  315. |*
  316. |* Beschreibung GEN.SDW
  317. |* Ersterstellung TH 19.03.90
  318. |* Letzte Aenderung MM 21.04.94
  319. |*
  320. *************************************************************************/
  321. BOOL Rectangle::IsInside( const Rectangle& rRect ) const
  322. {
  323. if ( IsInside( rRect.TopLeft() ) && IsInside( rRect.BottomRight() ) )
  324. return TRUE;
  325. else
  326. return FALSE;
  327. }
  328. /*************************************************************************
  329. |*
  330. |* Rectangle::IsOver()
  331. |*
  332. |* Beschreibung GEN.SDW
  333. |* Ersterstellung TH 19.03.90
  334. |* Letzte Aenderung MM 21.04.94
  335. |*
  336. *************************************************************************/
  337. BOOL Rectangle::IsOver( const Rectangle& rRect ) const
  338. {
  339. // Wenn sie sich nicht schneiden, ueberlappen sie auch nicht
  340. return !GetIntersection( rRect ).IsEmpty();
  341. }
  342. // =======================================================================
  343. SvStream& operator>>( SvStream& rIStream, Rectangle& rRect )
  344. {
  345. DBG_ASSERTWARNING( rIStream.GetVersion(), "Rectangle::>> - Solar-Version not set on rIStream" );
  346. if ( rIStream.GetCompressMode() == COMPRESSMODE_FULL )
  347. {
  348. unsigned char cIdAry[2];
  349. unsigned char cAry[16];
  350. int i;
  351. int iLast;
  352. int i1;
  353. int i2;
  354. int i3;
  355. int i4;
  356. UINT32 nNum;
  357. rIStream.Read( cIdAry, 2 );
  358. i1 = (cIdAry[0] & 0x70) >> 4;
  359. i2 = cIdAry[0] & 0x07;
  360. i3 = (cIdAry[1] & 0x70) >> 4;
  361. i4 = cIdAry[1] & 0x07;
  362. rIStream.Read( cAry, i1+i2+i3+i4 );
  363. nNum = 0;
  364. i = i1;
  365. iLast = i;
  366. while ( i )
  367. {
  368. i--;
  369. nNum <<= 8;
  370. nNum |= cAry[i];
  371. }
  372. iLast = i1;
  373. if ( cIdAry[0] & 0x80 )
  374. nNum ^= 0xFFFFFFFF;
  375. rRect.nLeft = (INT32)nNum;
  376. nNum = 0;
  377. i = iLast+i2;
  378. while ( i > iLast )
  379. {
  380. i--;
  381. nNum <<= 8;
  382. nNum |= cAry[i];
  383. }
  384. iLast += i2;
  385. if ( cIdAry[0] & 0x08 )
  386. nNum ^= 0xFFFFFFFF;
  387. rRect.nTop = (INT32)nNum;
  388. nNum = 0;
  389. i = iLast+i3;
  390. while ( i > iLast )
  391. {
  392. i--;
  393. nNum <<= 8;
  394. nNum |= cAry[i];
  395. }
  396. iLast += i3;
  397. if ( cIdAry[1] & 0x80 )
  398. nNum ^= 0xFFFFFFFF;
  399. rRect.nRight = (INT32)nNum;
  400. nNum = 0;
  401. i = iLast+i4;
  402. while ( i > iLast )
  403. {
  404. i--;
  405. nNum <<= 8;
  406. nNum |= cAry[i];
  407. }
  408. if ( cIdAry[1] & 0x08 )
  409. nNum ^= 0xFFFFFFFF;
  410. rRect.nBottom = (INT32)nNum;
  411. }
  412. else
  413. {
  414. rIStream >> rRect.nLeft >> rRect.nTop >> rRect.nRight >> rRect.nBottom;
  415. }
  416. return rIStream;
  417. }
  418. // -----------------------------------------------------------------------
  419. SvStream& operator<<( SvStream& rOStream, const Rectangle& rRect )
  420. {
  421. DBG_ASSERTWARNING( rOStream.GetVersion(), "Rectangle::<< - Solar-Version not set on rOStream" );
  422. if ( rOStream.GetCompressMode() == COMPRESSMODE_FULL )
  423. {
  424. unsigned char cAry[18];
  425. int i = 2;
  426. UINT32 nNum;
  427. cAry[0] = 0;
  428. cAry[1] = 0;
  429. nNum = (UINT32)(INT32)rRect.nLeft;
  430. if ( rRect.nLeft < 0 )
  431. {
  432. cAry[0] |= 0x80;
  433. nNum ^= 0xFFFFFFFF;
  434. }
  435. if ( nNum )
  436. {
  437. cAry[i] = (unsigned char)(nNum & 0xFF);
  438. nNum >>= 8;
  439. i++;
  440. if ( nNum )
  441. {
  442. cAry[i] = (unsigned char)(nNum & 0xFF);
  443. nNum >>= 8;
  444. i++;
  445. if ( nNum )
  446. {
  447. cAry[i] = (unsigned char)(nNum & 0xFF);
  448. nNum >>= 8;
  449. i++;
  450. if ( nNum )
  451. {
  452. cAry[i] = (unsigned char)(nNum & 0xFF);
  453. nNum >>= 8;
  454. i++;
  455. cAry[0] |= 0x40;
  456. }
  457. else
  458. cAry[0] |= 0x30;
  459. }
  460. else
  461. cAry[0] |= 0x20;
  462. }
  463. else
  464. cAry[0] |= 0x10;
  465. }
  466. nNum = (UINT32)(INT32)rRect.nTop;
  467. if ( rRect.nTop < 0 )
  468. {
  469. cAry[0] |= 0x08;
  470. nNum ^= 0xFFFFFFFF;
  471. }
  472. if ( nNum )
  473. {
  474. cAry[i] = (unsigned char)(nNum & 0xFF);
  475. nNum >>= 8;
  476. i++;
  477. if ( nNum )
  478. {
  479. cAry[i] = (unsigned char)(nNum & 0xFF);
  480. nNum >>= 8;
  481. i++;
  482. if ( nNum )
  483. {
  484. cAry[i] = (unsigned char)(nNum & 0xFF);
  485. nNum >>= 8;
  486. i++;
  487. if ( nNum )
  488. {
  489. cAry[i] = (unsigned char)(nNum & 0xFF);
  490. nNum >>= 8;
  491. i++;
  492. cAry[0] |= 0x04;
  493. }
  494. else
  495. cAry[0] |= 0x03;
  496. }
  497. else
  498. cAry[0] |= 0x02;
  499. }
  500. else
  501. cAry[0] |= 0x01;
  502. }
  503. nNum = (UINT32)(INT32)rRect.nRight;
  504. if ( rRect.nRight < 0 )
  505. {
  506. cAry[1] |= 0x80;
  507. nNum ^= 0xFFFFFFFF;
  508. }
  509. if ( nNum )
  510. {
  511. cAry[i] = (unsigned char)(nNum & 0xFF);
  512. nNum >>= 8;
  513. i++;
  514. if ( nNum )
  515. {
  516. cAry[i] = (unsigned char)(nNum & 0xFF);
  517. nNum >>= 8;
  518. i++;
  519. if ( nNum )
  520. {
  521. cAry[i] = (unsigned char)(nNum & 0xFF);
  522. nNum >>= 8;
  523. i++;
  524. if ( nNum )
  525. {
  526. cAry[i] = (unsigned char)(nNum & 0xFF);
  527. nNum >>= 8;
  528. i++;
  529. cAry[1] |= 0x40;
  530. }
  531. else
  532. cAry[1] |= 0x30;
  533. }
  534. else
  535. cAry[1] |= 0x20;
  536. }
  537. else
  538. cAry[1] |= 0x10;
  539. }
  540. nNum = (UINT32)(INT32)rRect.nBottom;
  541. if ( rRect.nBottom < 0 )
  542. {
  543. cAry[1] |= 0x08;
  544. nNum ^= 0xFFFFFFFF;
  545. }
  546. if ( nNum )
  547. {
  548. cAry[i] = (unsigned char)(nNum & 0xFF);
  549. nNum >>= 8;
  550. i++;
  551. if ( nNum )
  552. {
  553. cAry[i] = (unsigned char)(nNum & 0xFF);
  554. nNum >>= 8;
  555. i++;
  556. if ( nNum )
  557. {
  558. cAry[i] = (unsigned char)(nNum & 0xFF);
  559. nNum >>= 8;
  560. i++;
  561. if ( nNum )
  562. {
  563. cAry[i] = (unsigned char)(nNum & 0xFF);
  564. nNum >>= 8;
  565. i++;
  566. cAry[1] |= 0x04;
  567. }
  568. else
  569. cAry[1] |= 0x03;
  570. }
  571. else
  572. cAry[1] |= 0x02;
  573. }
  574. else
  575. cAry[1] |= 0x01;
  576. }
  577. rOStream.Write( cAry, i );
  578. }
  579. else
  580. {
  581. rOStream << rRect.nLeft << rRect.nTop << rRect.nRight << rRect.nBottom;
  582. }
  583. return rOStream;
  584. }