Schrift.cpp 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. #include "Schrift.h"
  2. #include "Bild.h"
  3. #include "Text.h"
  4. #include "Scroll.h"
  5. #include "Globals.h"
  6. #ifdef WIN32
  7. #include <Windows.h>
  8. #endif
  9. #include "FrameworkMath.h"
  10. using namespace Framework;
  11. // Inhalt der Buchstabe Klasse aus Schrift.h
  12. // Konstruktor
  13. Buchstabe::Buchstabe()
  14. : size( 0, 0 ),
  15. pos( 0, 0 ),
  16. alpha( 0 ),
  17. schriftSize( 0 ),
  18. drawSg( 0 ),
  19. ref( 1 )
  20. {}
  21. // Destruktor
  22. Buchstabe::~Buchstabe()
  23. {
  24. if( alpha )
  25. delete[]alpha;
  26. }
  27. // nicht constant
  28. void Buchstabe::NeuBuchstabe( Punkt &size ) // Initialisierung
  29. {
  30. this->size = size;
  31. if( alpha )
  32. delete[]alpha;
  33. alpha = new unsigned char[ size.x * size.y ];
  34. ZeroMemory( alpha, size.x * size.y );
  35. }
  36. void Buchstabe::setPixel( Punkt &pos, unsigned char alpha ) // setzt den alphawert des Pixels
  37. {
  38. this->alpha[ pos.x + pos.y * size.x ] = alpha;
  39. }
  40. void Buchstabe::setPixel( int x, int y, unsigned char alpha )
  41. {
  42. this->alpha[ x + y * size.x ] = alpha;
  43. }
  44. void Buchstabe::setPixel( int i, unsigned char alpha )
  45. {
  46. this->alpha[ i ] = alpha;
  47. }
  48. void Buchstabe::setPosition( Punkt &pos ) // setzt die Buchstabenposition
  49. {
  50. this->pos = pos;
  51. }
  52. void Buchstabe::setPosition( int x, int y )
  53. {
  54. pos.x = x;
  55. pos.y = y;
  56. }
  57. void Buchstabe::setSchriftSize( int sg ) // setzt die Schriftgröße des Buchstaben
  58. {
  59. schriftSize = sg;
  60. }
  61. void Buchstabe::setDrawSchriftSize( int dsg ) // setzt die Zeichengröße des Buchstaben
  62. {
  63. drawSg = dsg;
  64. }
  65. // constant
  66. const Punkt &Buchstabe::getSize() const // gibt die Buchstabenbildgröße zurück
  67. {
  68. return size;
  69. }
  70. int Buchstabe::getBreite() const // Buchstabenbreite
  71. {
  72. return (int)( ( (double)size.x / (double)schriftSize ) * (double)drawSg + 0.5 );
  73. }
  74. int Buchstabe::getHeight() const // Buchstabenhöhe
  75. {
  76. return (int)( ( (double)size.y / (double)schriftSize ) *(double)drawSg + 0.5 );
  77. }
  78. int Buchstabe::getNormHeight() const // Buchstabenhöhe
  79. {
  80. return size.y;
  81. }
  82. unsigned char *Buchstabe::getBuff() const // gibt den Alphabuffer zurück
  83. {
  84. return alpha;
  85. }
  86. void Buchstabe::render( Bild &zRObj, int f ) const // Zeichnet nach zRObj
  87. {
  88. if( alpha )
  89. {
  90. const Punkt &zRObjGr = zRObj.getDrawGr();
  91. const Punkt &zRObjPos = zRObj.getDrawPos();
  92. const Punkt &zRObjOff = zRObj.getDrawOff();
  93. int xp = pos.x + zRObjOff.x, yp = pos.y + zRObjOff.y;
  94. int xs = xp < zRObjPos.x ? ( zRObjPos.x - xp ) : 0, ys = yp < zRObjPos.y ? ( zRObjPos.y - yp ) : 0;
  95. int b = size.x, h = size.y;
  96. unsigned char a2 = (unsigned char)( 255 - ( f >> 24 ) );
  97. f &= 0x00FFFFFF;
  98. if( schriftSize == drawSg )
  99. {
  100. if( xp >= zRObjGr.x || yp >= zRObjGr.y || xp + b < zRObjPos.x || yp + h < zRObjPos.y )
  101. return;
  102. b = ( xp + b ) > zRObjGr.x ? ( zRObjGr.x - xp ) : b;
  103. h = ( yp + h ) > zRObjGr.y ? ( zRObjGr.y - yp ) : h;
  104. if( !a2 )
  105. {
  106. int xx, ygr = ( ys - 1 ) * size.x, ygr2 = ( yp + ys - 1 ) * zRObj.getBreite();
  107. for( int yy = ys; yy < h; ++yy )
  108. {
  109. ygr += size.x;
  110. ygr2 += zRObj.getBreite();
  111. for( xx = xs; xx < b; ++xx )
  112. zRObj.alphaPixel( xp + xx + ygr2, f | ( alpha[ xx + ygr ] << 24 ) );
  113. }
  114. }
  115. else
  116. {
  117. int a;
  118. int xx, ygr = ( ys - 1 ) * size.x, ygr2 = ( yp + ys - 1 ) * zRObj.getBreite();
  119. for( int yy = ys; yy < h; ++yy )
  120. {
  121. ygr += size.x;
  122. ygr2 += zRObj.getBreite();
  123. for( xx = xs; xx < b; ++xx )
  124. {
  125. a = alpha[ xx + ygr ] - a2;
  126. if( a > 0 )
  127. zRObj.alphaPixel( xp + xx + ygr2, f | ( a << 24 ) );
  128. }
  129. }
  130. }
  131. }
  132. else
  133. {
  134. double xoff = (double)schriftSize / (double)drawSg,
  135. yoff = (double)schriftSize / (double)drawSg;
  136. double x = xs * xoff, y = ys * yoff;
  137. int maxX = getBreite(), maxY = getHeight();
  138. maxX = ( xp + maxX ) >= zRObjGr.x ? ( zRObjGr.x - xp ) : maxX;
  139. maxY = ( yp + maxY ) >= zRObjGr.y ? ( zRObjGr.y - yp ) : maxY;
  140. if( !a2 )
  141. {
  142. int dx, ygr, ygr2;
  143. for( int dy = ys; dy < maxY; ++dy )
  144. {
  145. ygr2 = ( yp + dy ) * zRObj.getBreite();
  146. ygr = (int)y * b;
  147. for( dx = xs; dx < maxX; ++dx )
  148. {
  149. zRObj.alphaPixel( xp + dx + ygr2, f | ( alpha[ (int)x + ygr ] << 24 ) );
  150. x += xoff;
  151. }
  152. x = xs;
  153. y += yoff;
  154. }
  155. }
  156. else
  157. {
  158. int a, dx, ygr, ygr2;
  159. for( int dy = ys; dy < maxY; ++dy )
  160. {
  161. ygr2 = ( yp + dy ) * zRObj.getBreite();
  162. ygr = (int)y * b;
  163. for( dx = xs; dx < maxX; ++dx )
  164. {
  165. a = alpha[ (int)x + ygr ] - a2;
  166. zRObj.alphaPixel( xp + dx + ygr2, f | ( a << 24 ) );
  167. x += xoff;
  168. }
  169. x = xs;
  170. y += yoff;
  171. }
  172. }
  173. }
  174. }
  175. }
  176. // Reference Counting
  177. Buchstabe *Buchstabe::getThis()
  178. {
  179. ++ref;
  180. return this;
  181. }
  182. Buchstabe *Buchstabe::release()
  183. {
  184. --ref;
  185. if( ref == 0 )
  186. delete this;
  187. return 0;
  188. }
  189. // Inhalt der Alphabet Klasse aus Schrift.h
  190. // Konstruktor
  191. Alphabet::Alphabet()
  192. : zeichen( new Buchstabe*[ 256 ] ),
  193. schriftSize( 12 ),
  194. drawSchriftSize( 12 ),
  195. pos( 0, 0 ),
  196. zeilenHeight( 0 ),
  197. zeilenAbstand( 5 ),
  198. ref( 1 )
  199. {
  200. for( int i = 0; i < 256; ++i )
  201. zeichen[ i ] = 0;
  202. }
  203. // Destruktor
  204. Alphabet::~Alphabet()
  205. {
  206. for( int i = 0; i < 256; ++i )
  207. {
  208. if( zeichen[ i ] )
  209. zeichen[ i ]->release();
  210. }
  211. delete[]zeichen;
  212. }
  213. // nicht constant
  214. void Alphabet::NeuAlphabet() // Initialisierung
  215. {
  216. for( int i = 0; i < 256; ++i )
  217. {
  218. if( zeichen[ i ] )
  219. zeichen[ i ]->release();
  220. }
  221. for( int i = 0; i < 256; ++i )
  222. zeichen[ i ] = 0;
  223. zeilenHeight = 0;
  224. }
  225. void Alphabet::setBuchstabe( unsigned char i, Buchstabe *buchstabe ) // setzt einen Buchstaben
  226. {
  227. if( zeichen[ i ] )
  228. zeichen[ i ]->release();
  229. zeichen[ i ] = buchstabe;
  230. if( zeichen[ i ] )
  231. {
  232. zeichen[ i ]->setSchriftSize( schriftSize );
  233. zeichen[ i ]->setDrawSchriftSize( drawSchriftSize );
  234. }
  235. zeilenHeight = 0;
  236. for( int i = 0; i < 256; ++i )
  237. {
  238. if( zeichen[ i ] != 0 )
  239. zeilenHeight = maxInt( zeichen[ i ]->getHeight(), zeilenHeight );
  240. }
  241. }
  242. void Alphabet::setSchriftSize( int gr ) // setzt die Schriftgröße
  243. {
  244. schriftSize = gr;
  245. for( int i = 0; i < 256; ++i )
  246. {
  247. if( zeichen[ i ] )
  248. zeichen[ i ]->setSchriftSize( gr );
  249. }
  250. }
  251. void Alphabet::setDrawSchriftSize( int gr ) // setzt die Zeichengröße
  252. {
  253. drawSchriftSize = gr;
  254. for( int i = 0; i < 256; ++i )
  255. {
  256. if( zeichen[ i ] )
  257. zeichen[ i ]->setDrawSchriftSize( gr );
  258. }
  259. }
  260. void Alphabet::setZeilenAbstand( int za ) // setzt die Zeilenhöhe( Zeilenabstand )
  261. {
  262. zeilenAbstand = za;
  263. }
  264. void Alphabet::setDrawPosition( Punkt &pos ) // setzt die Draw Position
  265. {
  266. this->pos = pos;
  267. }
  268. void Alphabet::setDrawPosition( int x, int y )
  269. {
  270. pos.x = x;
  271. pos.y = y;
  272. }
  273. // constant
  274. Buchstabe *Alphabet::getBuchstabe( unsigned char i ) const // gibt einen Buchstaben zurück
  275. {
  276. if( zeichen[ i ] )
  277. return zeichen[ i ]->getThis();
  278. return 0;
  279. }
  280. Buchstabe *Alphabet::zBuchstabe( unsigned char i ) const
  281. {
  282. return zeichen[ i ];
  283. }
  284. bool Alphabet::hatBuchstabe( unsigned char b ) const
  285. {
  286. return zeichen[ b ] != 0;
  287. }
  288. int Alphabet::getSchriftSize() const // gibt die Schriftgröße zurück
  289. {
  290. return schriftSize;
  291. }
  292. int Alphabet::getDrawSchriftSize() const // gibt die Zeichengröße zurück
  293. {
  294. return drawSchriftSize;
  295. }
  296. int Alphabet::getZeilenAbstand() const // gibt den Zeilenabstand zurück
  297. {
  298. return zeilenAbstand;
  299. }
  300. int Alphabet::getZeilenHeight() const // gibt die Höhe des höchsten Zeichens zurück
  301. {
  302. return (int)( (double)zeilenHeight / schriftSize * drawSchriftSize + 0.5 );
  303. }
  304. const Punkt &Alphabet::getPosition() const // gibt die DrawPosition zurück
  305. {
  306. return pos;
  307. }
  308. int Alphabet::getTextBreite( Text *zTxt ) const // gibt die Breite des Textes zurück
  309. {
  310. int ret = 0;
  311. int len = zTxt->getLength();
  312. char *buff = zTxt->getText();
  313. unsigned char c = 0;
  314. int tmp = 0;
  315. for( int i = 0; i < len; ++i )
  316. {
  317. c = (unsigned char)buff[ i ];
  318. if( buff[ i ] == '\n' )
  319. {
  320. if( tmp > ret )
  321. ret = tmp;
  322. tmp = 0;
  323. }
  324. else if( buff[ i ] == '\r' )
  325. {
  326. i += 10;
  327. continue;
  328. }
  329. else if( buff[ i ] == '\t' )
  330. tmp += drawSchriftSize;
  331. else if( buff[ i ] == ' ' )
  332. tmp += drawSchriftSize / 2;
  333. else if( zeichen[ c ] )
  334. tmp += zeichen[ c ]->getBreite();
  335. }
  336. if( tmp > ret )
  337. ret = tmp;
  338. return ret;
  339. }
  340. int Alphabet::getTextHeight( Text *zTxt ) const // gibt die Höhe des Textes zurück
  341. {
  342. int hi = getZeilenHeight();
  343. return hi + ( ( hi + zeilenAbstand ) * zTxt->anzahlVon( '\n' ) );
  344. }
  345. int Alphabet::textPos( Text *zText, int mausX, int mausY ) const // gibt den Buchstaben zurück, auf den die Maus zeigt
  346. {
  347. char *buffer = zText->getText();
  348. int len = zText->getLength();
  349. int tx = 0;
  350. int ty = 0;
  351. int sh = getZeilenHeight();
  352. if( mausX < 0 || mausY < 0 )
  353. return -1;
  354. for( int i = 0; i < len; ++i )
  355. {
  356. if( buffer[ i ] == '\n' )
  357. {
  358. ty += sh + zeilenAbstand;
  359. tx = 0;
  360. if( mausY < ty )
  361. return i;
  362. }
  363. if( buffer[ i ] == '\t' )
  364. tx += drawSchriftSize;
  365. if( buffer[ i ] == ' ' )
  366. tx += drawSchriftSize / 2;
  367. if( zeichen[ (unsigned char)buffer[ i ] ] )
  368. tx += zeichen[ (unsigned char)buffer[ i ] ]->getBreite();
  369. int txpl = 0;
  370. if( zeichen[ (unsigned char)buffer[ i + 1 ] ] )
  371. txpl = zeichen[ (unsigned char)buffer[ i + 1 ] ]->getBreite() / 2;
  372. if( mausX < tx - txpl && mausY < ty + sh + zeilenAbstand )
  373. return i;
  374. }
  375. if( mausY < ty + sh + zeilenAbstand )
  376. return len;
  377. return -1;
  378. }
  379. void Alphabet::textFormatieren( Text *zText, int maxBreite, int schriftSize ) // fügt zeilenumbrüche ein
  380. {
  381. int sg = drawSchriftSize;
  382. setDrawSchriftSize( schriftSize );
  383. int lastPos = -1;
  384. int len = zText->getLength();
  385. char *txt = zText->getText();
  386. int x = 0;
  387. Text result = zText->getText();
  388. for( int i = 0; i < len; ++i )
  389. {
  390. char c = txt[ i ];
  391. if( c == ' ' )
  392. {
  393. lastPos = i;
  394. x += schriftSize / 2;
  395. continue;
  396. }
  397. if( c == '\t' )
  398. {
  399. lastPos = i;
  400. x += schriftSize;
  401. continue;
  402. }
  403. if( c == '\n' )
  404. {
  405. x = 0;
  406. lastPos = -1;
  407. continue;
  408. }
  409. if( c == '\r' && len - i >= 11 )
  410. {
  411. i += 10;
  412. continue;
  413. }
  414. Buchstabe *b = getBuchstabe( (unsigned)c );
  415. if( b )
  416. {
  417. x += b->getBreite();
  418. if( x > maxBreite && lastPos > -1 )
  419. {
  420. result.ersetzen( lastPos, lastPos + 1, "\n" );
  421. x = 0;
  422. i = lastPos;
  423. lastPos = -1;
  424. }
  425. b = b->release();
  426. }
  427. }
  428. zText->setText( result );
  429. setDrawSchriftSize( sg );
  430. }
  431. void Alphabet::render( Text *zTxt, Bild &rendezRObj, int f ) const // Zeichnet txt nach rendezRObj
  432. {
  433. int zRObjBr = rendezRObj.getBreite();
  434. int zRObjHi = rendezRObj.getHeight();
  435. int xp = pos.x;
  436. int yp = pos.y;
  437. int zh = getZeilenHeight();
  438. if( yp + ( zh + zeilenAbstand ) * zTxt->anzahlVon( '\n' ) + zh < 0 || xp >= zRObjBr || yp >= zRObjHi )
  439. return;
  440. char *text = zTxt->getText();
  441. int len = zTxt->getLength();
  442. for( int i = 0; i < len; ++i )
  443. {
  444. unsigned char c = text[ i ];
  445. if( c == ' ' )
  446. {
  447. xp += drawSchriftSize / 2;
  448. continue;
  449. }
  450. if( c == '\t' )
  451. {
  452. xp += drawSchriftSize;
  453. continue;
  454. }
  455. if( c == '\n' )
  456. {
  457. yp += zh + zeilenAbstand;
  458. xp = pos.x;
  459. continue;
  460. }
  461. if( c == '\r' && len - i >= 11 )
  462. {
  463. i += 3;
  464. Text *hex1 = zTxt->getTeilText( i, i + 6 );
  465. Text *hex2 = zTxt->getTeilText( i + 6, i + 8 );
  466. f = ( TextZuInt( hex1->getText(), 16 ) << 8 ) |
  467. ( TextZuInt( hex2->getText(), 16 ) );
  468. hex1->release();
  469. hex2->release();
  470. i += 7;
  471. continue;
  472. }
  473. if( zeichen[ c ] )
  474. {
  475. if( xp >= zRObjBr )
  476. continue;
  477. zeichen[ c ]->setPosition( xp, yp );
  478. zeichen[ c ]->render( rendezRObj, f );
  479. xp += zeichen[ c ]->getBreite();
  480. }
  481. }
  482. }
  483. void Alphabet::render( Text *zTxt, Bild &rendezRObj, int cpos, int cf, int fbeg, int ff, int f ) const
  484. {
  485. int zRObjBr = rendezRObj.getBreite();
  486. int zRObjHi = rendezRObj.getHeight();
  487. int xp = pos.x;
  488. int yp = pos.y;
  489. int zh = getZeilenHeight();
  490. if( yp + ( zh + zeilenAbstand ) * zTxt->anzahlVon( '\n' ) + zh < 0 || xp >= zRObjBr || yp >= zRObjHi )
  491. return;
  492. char *text = zTxt->getText();
  493. int len = zTxt->getLength();
  494. bool faerb = 0;
  495. for( int i = 0; i < len; ++i )
  496. {
  497. unsigned char c = text[ i ];
  498. if( i == fbeg )
  499. faerb = !faerb;
  500. if( i == cpos )
  501. {
  502. rendezRObj.drawLinieVAlpha( xp, yp, zh, cf );
  503. faerb = !faerb;
  504. }
  505. if( c == ' ' )
  506. {
  507. if( faerb )
  508. rendezRObj.alphaRegion( xp, yp, drawSchriftSize / 2, zh, ff );
  509. xp += drawSchriftSize / 2;
  510. continue;
  511. }
  512. if( c == '\t' )
  513. {
  514. if( faerb )
  515. rendezRObj.alphaRegion( xp, yp, drawSchriftSize, zh, ff );
  516. xp += drawSchriftSize;
  517. continue;
  518. }
  519. if( c == '\n' )
  520. {
  521. yp += zh + zeilenAbstand;
  522. xp = pos.x;
  523. continue;
  524. }
  525. if( c == '\r' && len - i >= 11 )
  526. {
  527. i += 3;
  528. Text *hex1 = zTxt->getTeilText( i, i + 6 );
  529. Text *hex2 = zTxt->getTeilText( i + 6, i + 8 );
  530. f = ( TextZuInt( hex1->getText(), 16 ) << 8 ) |
  531. ( TextZuInt( hex2->getText(), 16 ) );
  532. hex1->release();
  533. hex2->release();
  534. i += 7;
  535. continue;
  536. }
  537. if( zeichen[ c ] )
  538. {
  539. if( xp >= zRObjBr )
  540. continue;
  541. if( faerb )
  542. {
  543. int br = zeichen[ c ]->getBreite();
  544. rendezRObj.alphaRegion( xp, yp, br, zh, ff );
  545. }
  546. zeichen[ c ]->setPosition( xp, yp );
  547. zeichen[ c ]->render( rendezRObj, f );
  548. xp += zeichen[ c ]->getBreite();
  549. }
  550. }
  551. if( len == cpos )
  552. rendezRObj.drawLinieVAlpha( xp, yp, zh, cf );
  553. }
  554. // Reference Counting
  555. Alphabet *Alphabet::getThis()
  556. {
  557. ++ref;
  558. return this;
  559. }
  560. Alphabet *Alphabet::release()
  561. {
  562. --ref;
  563. if( ref == 0 )
  564. delete this;
  565. return 0;
  566. }
  567. // Inhalt der AlphabetArray Klasse aus Schrift.h
  568. // Konstruktor
  569. AlphabetArray::AlphabetArray()
  570. : next( 0 ),
  571. This( 0 )
  572. {}
  573. // Destruktor
  574. AlphabetArray::~AlphabetArray()
  575. {
  576. if( This )
  577. This->release();
  578. delete next;
  579. }
  580. // nicht constant
  581. bool AlphabetArray::addAlphabet( Alphabet *alphabet ) // Fügt ein Alphabet hinzu
  582. {
  583. if( This )
  584. {
  585. if( This->getSchriftSize() == alphabet->getSchriftSize() )
  586. {
  587. alphabet->release();
  588. return false;
  589. }
  590. }
  591. else
  592. {
  593. This = alphabet;
  594. return true;
  595. }
  596. if( !next )
  597. next = new AlphabetArray();
  598. return next->addAlphabet( alphabet );
  599. }
  600. bool AlphabetArray::removeAlphabet( int sg ) // entfernt ein Alphabet
  601. {
  602. if( This )
  603. {
  604. if( This->getSchriftSize() == sg )
  605. This = This->release();
  606. return 1;
  607. }
  608. if( !next )
  609. return 0;
  610. if( next->removeAlphabet( sg ) )
  611. {
  612. AlphabetArray *tmp = next->getNext();
  613. next->setNext0();
  614. delete next;
  615. next = tmp;
  616. }
  617. return 0;
  618. }
  619. void AlphabetArray::setDrawSchriftSize( int sg ) // Setzt die Draw Schriftgröße aller Alphabete
  620. {
  621. if( This )
  622. This->setDrawSchriftSize( sg );
  623. if( next )
  624. next->setDrawSchriftSize( sg );
  625. }
  626. void AlphabetArray::setZeilenAbstand( int za ) // setzt den Zeilenabstant aller Alphabete
  627. {
  628. if( This )
  629. This->setZeilenAbstand( za );
  630. if( next )
  631. next->setZeilenAbstand( za );
  632. }
  633. void AlphabetArray::setNext0() // setzt den next Zeiger zu 0
  634. {
  635. next = 0;
  636. }
  637. // constant
  638. Alphabet *AlphabetArray::getAlphabet( unsigned char sg ) const // gibt getThis von einem Alphabet zurück
  639. {
  640. if( !This )
  641. return 0;
  642. if( This->getSchriftSize() == sg )
  643. return This->getThis();
  644. if( next )
  645. return next->getAlphabet( sg );
  646. return 0;
  647. }
  648. Alphabet *AlphabetArray::zAlphabet( unsigned char sg ) const // gibt ein Alphabet zurück
  649. {
  650. if( !This )
  651. return 0;
  652. if( This->getSchriftSize() == sg )
  653. return This;
  654. if( next )
  655. return next->zAlphabet( sg );
  656. return 0;
  657. }
  658. Alphabet *AlphabetArray::getAlphabetI( int index, int count ) const
  659. {
  660. if( count == index )
  661. return This->getThis();
  662. if( next )
  663. return next->getAlphabetI( index, count + 1 );
  664. return 0;
  665. }
  666. Alphabet *AlphabetArray::zAlphabetI( int index, int count ) const
  667. {
  668. if( count == index )
  669. return This;
  670. if( next )
  671. return next->zAlphabetI( index, count + 1 );
  672. return 0;
  673. }
  674. AlphabetArray *AlphabetArray::getNext() const // gibt das nächste Alphabet zurück
  675. {
  676. return next;
  677. }
  678. // Inhalt der Schrift Klasse aus Schrift.h
  679. // Konstruktor
  680. Schrift::Schrift()
  681. : alphabetAnzahl( 0 ),
  682. alphabet( new AlphabetArray() ),
  683. schriftSize( 12 ),
  684. zeilenAbstand( 5 ),
  685. drawPos( 0, 0 ),
  686. ref( 1 )
  687. {
  688. InitializeCriticalSection( &cs );
  689. }
  690. // Destruktor
  691. Schrift::~Schrift()
  692. {
  693. delete alphabet;
  694. DeleteCriticalSection( &cs );
  695. }
  696. // nicht constant
  697. void Schrift::lock() // lockt die Schrift
  698. {
  699. EnterCriticalSection( &cs );
  700. }
  701. void Schrift::unlock() // unlockt die Schrift
  702. {
  703. LeaveCriticalSection( &cs );
  704. }
  705. bool Schrift::addAlphabet( Alphabet *alphabet ) // Fügt der Schrift ein Alphabet hinzu
  706. {
  707. lock();
  708. if( this->alphabet->addAlphabet( alphabet ) )
  709. {
  710. ++alphabetAnzahl;
  711. alphabet->setDrawSchriftSize( schriftSize );
  712. unlock();
  713. return true;
  714. }
  715. unlock();
  716. return false;
  717. }
  718. void Schrift::removeAlphabet( int sg ) // Entfernt ein Alphabet
  719. {
  720. lock();
  721. if( alphabet->removeAlphabet( sg ) )
  722. --alphabetAnzahl;
  723. unlock();
  724. }
  725. void Schrift::setDrawPosition( int x, int y ) // setzt die Zeichenposition
  726. {
  727. lock();
  728. drawPos.x = x;
  729. drawPos.y = y;
  730. unlock();
  731. }
  732. void Schrift::setDrawPosition( Punkt &pos )
  733. {
  734. lock();
  735. drawPos = pos;
  736. unlock();
  737. }
  738. void Schrift::setSchriftSize( int sg ) // setzt die Schriftgröße
  739. {
  740. lock();
  741. schriftSize = sg;
  742. alphabet->setDrawSchriftSize( sg );
  743. unlock();
  744. }
  745. void Schrift::setZeilenAbstand( int za ) // setzt den Zeilenabstand
  746. {
  747. lock();
  748. zeilenAbstand = za;
  749. alphabet->setZeilenAbstand( za );
  750. unlock();
  751. }
  752. void Schrift::textFormatieren( Text *zText, int maxBreite, int schriftSize ) // fügt zeilenumbrüche ein
  753. {
  754. lock();
  755. Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
  756. if( !drawAlphabet )
  757. {
  758. for( int i = 0; i < 256; ++i )
  759. {
  760. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
  761. if( drawAlphabet )
  762. break;
  763. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
  764. if( drawAlphabet )
  765. break;
  766. }
  767. }
  768. if( drawAlphabet )
  769. drawAlphabet->textFormatieren( zText, maxBreite, schriftSize );
  770. unlock();
  771. }
  772. void Schrift::renderText( Text *zTxt, Bild &zRObj, int f ) // zeichnet txt nach zRObj
  773. {
  774. lock();
  775. Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
  776. if( !drawAlphabet )
  777. {
  778. for( int i = 0; i < 256; ++i )
  779. {
  780. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
  781. if( drawAlphabet )
  782. break;
  783. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
  784. if( drawAlphabet )
  785. break;
  786. }
  787. }
  788. if( drawAlphabet )
  789. {
  790. drawAlphabet->setDrawPosition( drawPos.x, drawPos.y );
  791. drawAlphabet->render( zTxt, zRObj, f );
  792. }
  793. unlock();
  794. }
  795. void Schrift::renderText( Text *zTxt, Bild &zRObj, int cpos, int cf, int fbeg, int ff, int f )
  796. {
  797. lock();
  798. Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
  799. if( !drawAlphabet )
  800. {
  801. for( int i = 0; i < 256; ++i )
  802. {
  803. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
  804. if( drawAlphabet )
  805. break;
  806. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
  807. if( drawAlphabet )
  808. break;
  809. }
  810. }
  811. if( drawAlphabet )
  812. {
  813. drawAlphabet->setDrawPosition( drawPos.x, drawPos.y );
  814. drawAlphabet->render( zTxt, zRObj, cpos, cf, fbeg, ff, f );
  815. }
  816. unlock();
  817. }
  818. // constant
  819. Alphabet *Schrift::getAlphabet( int sg ) const // gibt einen Alphaberarray zurück
  820. {
  821. return alphabet->getAlphabet( (unsigned char)sg );
  822. }
  823. Alphabet *Schrift::zAlphabet( int sg ) const
  824. {
  825. return alphabet->zAlphabet( (unsigned char)sg );
  826. }
  827. Alphabet *Schrift::getAlphabetI( int index ) const
  828. {
  829. return alphabet->getAlphabetI( index, 0 );
  830. }
  831. Alphabet *Schrift::zAlphabetI( int index ) const
  832. {
  833. return alphabet->zAlphabetI( index, 0 );
  834. }
  835. unsigned char Schrift::getAlphabetAnzahl() const // gibt die anzahl von in der Schrift enthaltenen Alphabeten zurück
  836. {
  837. return alphabetAnzahl;
  838. }
  839. int Schrift::getSchriftSize() const // gibt die Schriftgröße zurück
  840. {
  841. return schriftSize;
  842. }
  843. int Schrift::getZeilenabstand() const // gibt den Zeilenabstand zurück
  844. {
  845. return zeilenAbstand;
  846. }
  847. int Schrift::getDrawX() const // gibt die Zeichenposition zurück
  848. {
  849. return drawPos.x;
  850. }
  851. int Schrift::getDrawY() const
  852. {
  853. return drawPos.y;
  854. }
  855. const Punkt &Schrift::getDrawPosition() const
  856. {
  857. return drawPos;
  858. }
  859. int Schrift::getTextBreite( Text *zTxt ) const // gibt die Breite des Textes zurück
  860. {
  861. Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
  862. if( !drawAlphabet )
  863. {
  864. for( int i = 0; i < 256; ++i )
  865. {
  866. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
  867. if( drawAlphabet )
  868. break;
  869. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
  870. if( drawAlphabet )
  871. break;
  872. }
  873. }
  874. if( !drawAlphabet )
  875. return 0;
  876. return drawAlphabet->getTextBreite( zTxt );
  877. }
  878. int Schrift::getTextHeight( Text *zTxt ) const // gibt die Höhe des Textes zurück
  879. {
  880. Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
  881. if( !drawAlphabet )
  882. {
  883. for( int i = 0; i < 256; ++i )
  884. {
  885. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
  886. if( drawAlphabet )
  887. break;
  888. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
  889. if( drawAlphabet )
  890. break;
  891. }
  892. }
  893. if( !drawAlphabet )
  894. return 0;
  895. return drawAlphabet->getTextHeight( zTxt );
  896. }
  897. int Schrift::textPos( Text *zTxt, int mausX, int mausY ) const // gibt den Buchstaben zurück, auf den die Maus zeigt
  898. {
  899. Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
  900. if( !drawAlphabet )
  901. {
  902. for( int i = 0; i < 256; ++i )
  903. {
  904. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
  905. if( drawAlphabet )
  906. break;
  907. drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
  908. if( drawAlphabet )
  909. break;
  910. }
  911. }
  912. if( !drawAlphabet )
  913. return 0;
  914. return drawAlphabet->textPos( zTxt, mausX, mausY );
  915. }
  916. // Reference Counting
  917. Schrift *Schrift::getThis()
  918. {
  919. ++ref;
  920. return this;
  921. }
  922. Schrift *Schrift::release()
  923. {
  924. --ref;
  925. if( ref == 0 )
  926. delete this;
  927. return 0;
  928. }