lcd_buf_draw.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768
  1. /*
  2. * Copyright (c) 2009 Openmoko Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdio.h>
  18. #include <stddef.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <inttypes.h>
  22. #ifdef WIKIPCF
  23. #include <wchar.h>
  24. #include <malloc.h>
  25. #include <fcntl.h>
  26. #include <unistd.h>
  27. #else
  28. #include <file-io.h>
  29. #include <guilib.h>
  30. #include <malloc-simple.h>
  31. #include <msg.h>
  32. #include <lcd.h>
  33. #include <input.h>
  34. #include "delay.h"
  35. #include <tick.h>
  36. #include "history.h"
  37. #include "search.h"
  38. #include "glyph.h"
  39. #include "wikilib.h"
  40. #include "restricted.h"
  41. #include "wiki_info.h"
  42. #endif
  43. #include "bmf.h"
  44. #include "lcd_buf_draw.h"
  45. #include "search.h"
  46. #include "bigram.h"
  47. #define MAX_SCROLL_SECONDS 3
  48. #define LIST_SCROLL_SPEED_FRICTION 0.3
  49. #define ARTICLE_SCROLL_SPEED_FRICTION 0.3
  50. #define SCROLL_UNIT_SECOND 0.1
  51. #define LINK_INVERT_ACTIVATION_TIME_THRESHOLD 0.1
  52. #define LIST_LINK_INVERT_ACTIVATION_TIME_THRESHOLD 0.35
  53. #define RESTRICTED_MARK_LINK 0xFFFFFF
  54. #define PREVIOUS_ARTICLE_LINK 0xFFFFFE
  55. #define EXTERNAL_ARTICLE_LINK 0xFFFFFD
  56. #define SHOW_LANGUAGE_LINK 0xFFFFFC
  57. #define HIDE_LANGUAGE_LINK 0xFFFFFB
  58. #define PREVIOUS_ARTICLE_LINKABLE_SIZE 20
  59. #define ARTICLE_LINK_SOMETHING_BEFORE 0x20
  60. #define ARTICLE_LINK_NOTHING_BEFORE 0x10
  61. #define ARTICLE_LINK_SOMETHING_AFTER 0x02
  62. #define ARTICLE_LINK_NOTHING_AFTER 0x01
  63. #ifndef WIKIPCF
  64. extern long finger_move_speed;
  65. extern int last_display_mode;
  66. extern int display_mode;
  67. #endif
  68. pcffont_bmf_t pcfFonts[FONT_COUNT];
  69. static int lcd_draw_buf_inited = 0;
  70. LCD_DRAW_BUF lcd_draw_buf;
  71. unsigned char * file_buffer;
  72. int restricted_article = 0;
  73. int lcd_draw_buf_pos = 0;
  74. int lcd_draw_cur_y_pos = 0;
  75. int lcd_draw_init_y_pos = 0;
  76. int request_display_next_page = 0;
  77. int request_y_pos = 0;
  78. int cur_render_y_pos = 0;
  79. int article_start_y_pos = 0;
  80. int bShowLanguageLinks = 0;
  81. int bShowPositioner = 0;
  82. ARTICLE_LINK articleLink[MAX_ARTICLE_LINKS];
  83. EXTERNAL_LINK externalLink[MAX_EXTERNAL_LINKS];
  84. char articleLinkBeforeAfter[MAX_ARTICLE_LINKS];
  85. #ifndef WIKIPCF
  86. int link_to_be_activated = -1;
  87. unsigned long link_to_be_activated_start_time = 0;
  88. int link_to_be_inverted = -1;
  89. unsigned long link_to_be_inverted_start_time = 0;
  90. int link_currently_activated = -1;
  91. int link_currently_inverted = -1;
  92. #endif
  93. int article_link_count;
  94. int language_link_count;
  95. int display_first_page = 0;
  96. void display_link_article(long idx_article);
  97. void drawline_in_framebuffer_copy(unsigned char *buffer,int start_x,int start_y,int end_x,int end_y);
  98. void buf_draw_char_external(LCD_DRAW_BUF *lcd_draw_buf_external,ucs4_t u,int start_x,int end_x,int start_y,int end_y);
  99. void repaint_framebuffer(unsigned char *buf, int pos, int b_repaint_invert_link);
  100. void repaint_invert_link(void);
  101. char* FontFile(int idx);
  102. void msg_info(char *data);
  103. int framebuffer_size();
  104. int framebuffer_width();
  105. int framebuffer_height();
  106. unsigned char *framebuffer_copy;
  107. char msg_out[1024];
  108. extern unsigned char *framebuffer;
  109. long article_scroll_increment;
  110. unsigned long time_scroll_article_last=0;
  111. int stop_render_article = 0;
  112. int b_show_scroll_bar = 0;
  113. long saved_idx_article = 0;
  114. long saved_prev_idx_article = 0;
  115. #define MIN_BAR_LEN 20
  116. #ifndef WIKIPCF
  117. void show_scroll_bar(int bShow)
  118. {
  119. int bar_len;
  120. int bar_pos;
  121. int i;
  122. int byte_idx;
  123. char c;
  124. static char frame_bytes[LCD_HEIGHT_LINES];
  125. static int b_frame_bytes;
  126. if (lcd_draw_buf.current_y < LCD_HEIGHT_LINES)
  127. return;
  128. if (bShow <= 0)
  129. {
  130. if (b_frame_bytes)
  131. {
  132. if (!bShow && finger_move_speed == 0)
  133. {
  134. #ifdef INCLUDED_FROM_KERNEL
  135. //delay_us(10000);
  136. #endif
  137. }
  138. for (i = 0; i < LCD_HEIGHT_LINES; i++)
  139. {
  140. byte_idx = (236 + LCD_VRAM_WIDTH_PIXELS * i) / 8;
  141. framebuffer[byte_idx] = frame_bytes[i];
  142. }
  143. b_frame_bytes = 0;
  144. }
  145. }
  146. else
  147. {
  148. bar_len = LCD_HEIGHT_LINES * LCD_HEIGHT_LINES / lcd_draw_buf.current_y;
  149. if (bar_len > LCD_HEIGHT_LINES)
  150. bar_len = LCD_HEIGHT_LINES;
  151. else if (bar_len < MIN_BAR_LEN)
  152. bar_len = MIN_BAR_LEN;
  153. if (lcd_draw_buf.current_y > LCD_HEIGHT_LINES)
  154. bar_pos = (LCD_HEIGHT_LINES - bar_len) * lcd_draw_cur_y_pos / (lcd_draw_buf.current_y - LCD_HEIGHT_LINES);
  155. else
  156. bar_pos = 0;
  157. if (bar_pos < 0)
  158. bar_pos = 0;
  159. else if (bar_pos + bar_len > LCD_HEIGHT_LINES)
  160. bar_pos = LCD_HEIGHT_LINES - bar_len;
  161. for (i = 0; i < LCD_HEIGHT_LINES; i++)
  162. {
  163. if (bar_pos <= i && i < bar_pos + bar_len)
  164. c = 0x07;
  165. else
  166. c = 0;
  167. byte_idx = (236 + LCD_VRAM_WIDTH_PIXELS * i) / 8;
  168. frame_bytes[i] = framebuffer[byte_idx];
  169. framebuffer[byte_idx] = (framebuffer[byte_idx] & 0xF0) | c;
  170. }
  171. b_frame_bytes = 1;
  172. }
  173. }
  174. #endif
  175. void init_lcd_draw_buf()
  176. {
  177. int i,framebuffersize,fd;
  178. if (!lcd_draw_buf_inited)
  179. {
  180. framebuffersize = framebuffer_size();
  181. framebuffer_copy = (unsigned char*)Xalloc(framebuffersize);
  182. lcd_draw_buf.screen_buf = (unsigned char *)Xalloc(LCD_BUF_WIDTH_BYTES * LCD_BUF_HEIGHT_PIXELS);
  183. for (i=0; i < FONT_COUNT; i++)
  184. {
  185. pcfFonts[i].file = FontFile(i);
  186. if (!pcfFonts[i].file[0])
  187. {
  188. pcfFonts[i].fd = -1;
  189. }
  190. else
  191. {
  192. fd = load_bmf(&pcfFonts[i]);
  193. if(fd >= 0)
  194. {
  195. if (i == ITALIC_FONT_IDX - 1)
  196. {
  197. pcfFonts[i].bPartialFont = 1;
  198. pcfFonts[i].supplement_font = &pcfFonts[DEFAULT_ALL_FONT_IDX - 1];
  199. }
  200. else if (i == DEFAULT_FONT_IDX - 1)
  201. {
  202. pcfFonts[i].bPartialFont = 1;
  203. pcfFonts[i].supplement_font = &pcfFonts[DEFAULT_ALL_FONT_IDX - 1];
  204. }
  205. else if (i == TITLE_FONT_IDX - 1)
  206. {
  207. pcfFonts[i].bPartialFont = 1;
  208. pcfFonts[i].supplement_font = &pcfFonts[TITLE_ALL_FONT_IDX - 1];
  209. }
  210. else if (i == SUBTITLE_FONT_IDX - 1)
  211. {
  212. pcfFonts[i].bPartialFont = 1;
  213. pcfFonts[i].supplement_font = &pcfFonts[SUBTITLE_ALL_FONT_IDX - 1];
  214. }
  215. else
  216. {
  217. pcfFonts[i].bPartialFont = 0;
  218. }
  219. pcfFonts[i].fd = fd;
  220. }
  221. #if !defined(INCLUDED_FROM_KERNEL)
  222. else
  223. {
  224. printf("Missing font: '%s'\n", pcfFonts[i].file);
  225. exit(1);
  226. }
  227. #endif
  228. }
  229. }
  230. lcd_draw_buf_inited = 1;
  231. }
  232. lcd_draw_buf.current_x = 0;
  233. lcd_draw_buf.current_y = 0;
  234. lcd_draw_buf.drawing = 0;
  235. lcd_draw_buf.pPcfFont = NULL;
  236. lcd_draw_buf.line_height = 0;
  237. lcd_draw_buf.align_adjustment = 0;
  238. if (lcd_draw_buf.screen_buf)
  239. memset(lcd_draw_buf.screen_buf, 0, LCD_BUF_WIDTH_BYTES * LCD_BUF_HEIGHT_PIXELS);
  240. }
  241. void draw_string(unsigned char *s)
  242. {
  243. //ucs4_t u;
  244. unsigned char **p = &s;
  245. buf_draw_UTF8_str(p);
  246. //while (**p && (u = UTF8_to_UCS4(p)))
  247. //{
  248. // buf_draw_char(u);
  249. //}
  250. }
  251. void draw_article_positioner(int y_pos)
  252. {
  253. static int last_positioner_y = 0;
  254. if (!bShowPositioner)
  255. return;
  256. if (y_pos == 0)
  257. last_positioner_y = article_start_y_pos;
  258. else
  259. {
  260. while (y_pos - last_positioner_y - article_start_y_pos > LCD_HEIGHT_LINES / 2)
  261. {
  262. last_positioner_y += LCD_HEIGHT_LINES / 2;
  263. lcd_set_pixel(lcd_draw_buf.screen_buf, 0, last_positioner_y - 2);
  264. lcd_set_pixel(lcd_draw_buf.screen_buf, 0, last_positioner_y - 1);
  265. lcd_set_pixel(lcd_draw_buf.screen_buf, 1, last_positioner_y - 1);
  266. lcd_set_pixel(lcd_draw_buf.screen_buf, 0, last_positioner_y);
  267. lcd_set_pixel(lcd_draw_buf.screen_buf, 1, last_positioner_y);
  268. lcd_set_pixel(lcd_draw_buf.screen_buf, 2, last_positioner_y);
  269. lcd_set_pixel(lcd_draw_buf.screen_buf, 0, last_positioner_y + 1);
  270. lcd_set_pixel(lcd_draw_buf.screen_buf, 1, last_positioner_y + 1);
  271. lcd_set_pixel(lcd_draw_buf.screen_buf, 0, last_positioner_y + 2);
  272. }
  273. }
  274. }
  275. void init_file_buffer()
  276. {
  277. file_buffer = (unsigned char*)Xalloc(FILE_BUFFER_SIZE);
  278. }
  279. // default font is indexed 0, font id 0 is indexed 1, etc.
  280. char* FontFile(int idx) {
  281. switch(idx)
  282. {
  283. case ITALIC_FONT_IDX - 1:
  284. return FONT_FILE_ITALIC;
  285. break;
  286. case DEFAULT_FONT_IDX - 1:
  287. return FONT_FILE_DEFAULT;
  288. break;
  289. case DEFAULT_ALL_FONT_IDX - 1:
  290. return FONT_FILE_DEFAULT_ALL;
  291. break;
  292. case TITLE_FONT_IDX - 1:
  293. return FONT_FILE_TITLE;
  294. break;
  295. case SUBTITLE_FONT_IDX - 1:
  296. return FONT_FILE_SUBTITLE;
  297. break;
  298. case TITLE_ALL_FONT_IDX - 1:
  299. return FONT_FILE_TITLE_ALL;
  300. break;
  301. case SUBTITLE_ALL_FONT_IDX - 1:
  302. return FONT_FILE_SUBTITLE_ALL;
  303. break;
  304. default:
  305. return "";
  306. break;
  307. }
  308. }
  309. ucs4_t UTF8_to_UCS4(unsigned char **pUTF8)
  310. {
  311. ucs4_t c0, c1, c2, c3;
  312. /* if 0 returned, it is not a invalid UTF8 character. The pointer moves to the second byte. */
  313. c0 = 0;
  314. if (**pUTF8)
  315. {
  316. c0 = (ucs4_t)**pUTF8;
  317. (*pUTF8)++;
  318. if (c0 & 0x80) /* multi-byte UTF8 char */
  319. {
  320. if ((c0 & 0xE0) == 0xC0) /* 2-byte UTF8 */
  321. {
  322. c1 = **pUTF8;
  323. if ((c1 & 0xC0) == 0x80)
  324. {
  325. (*pUTF8)++;
  326. c0 = ((c0 & 0x1F) << 6) + (c1 & 0x3F);
  327. }
  328. else
  329. c0 = 0; /* invalid UTF8 character */
  330. }
  331. else if ((c0 & 0xF0) == 0xE0) /* 3-byte UTF8 */
  332. {
  333. c1 = **pUTF8;
  334. c2 = *(*pUTF8 + 1);
  335. if ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80)
  336. {
  337. (*pUTF8) += 2;
  338. c0 = ((c0 & 0x0F) << 12) + ((c1 & 0x3F) << 6) + (c2 & 0x3F);
  339. }
  340. else
  341. c0 = 0; /* invalid UTF8 character */
  342. }
  343. else if ((c0 & 0xF1) == 0xF0) /* 4-byte UTF8 */
  344. {
  345. c1 = **pUTF8;
  346. c2 = *(*pUTF8 + 1);
  347. c3 = *(*pUTF8 + 2);
  348. if ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80 && (c3 & 0xC0) == 0x80)
  349. {
  350. (*pUTF8) += 3;
  351. c0 = ((c0 & 0x07) << 18) + ((c1 & 0x3F) << 12) + ((c2 & 0x3F) << 6) + (c3 & 0x3F) ;
  352. }
  353. else
  354. c0 = 0; /* invalid UTF8 character */
  355. }
  356. else
  357. c0 = 0; /* invalid UTF8 character */
  358. }
  359. }
  360. return c0;
  361. }
  362. void UCS4_to_UTF8(ucs4_t u, unsigned char *sUTF8)
  363. {
  364. if (u < 0x80)
  365. {
  366. sUTF8[0] = (unsigned char)u;
  367. sUTF8[1] = '\0';
  368. }
  369. else if (u < 0x800)
  370. {
  371. sUTF8[0] = (unsigned char)(0xC0 | (u >> 6));
  372. sUTF8[1] = (unsigned char)(0x80 | (u & 0x3F));
  373. sUTF8[2] = '\0';
  374. }
  375. else if (u < 0x10000)
  376. {
  377. sUTF8[0] = (unsigned char)(0xC0 | (u >> 12));
  378. sUTF8[1] = (unsigned char)(0x80 | ((u & 0xFFF) >> 6));
  379. sUTF8[2] = (unsigned char)(0x80 | (u & 0x3F));
  380. sUTF8[3] = '\0';
  381. }
  382. else if (u < 0x110000)
  383. {
  384. sUTF8[0] = (unsigned char)(0xC0 | (u >> 18));
  385. sUTF8[1] = (unsigned char)(0x80 | ((u & 0x3FFFF) >> 12));
  386. sUTF8[2] = (unsigned char)(0x80 | ((u & 0xFFF) >> 6));
  387. sUTF8[3] = (unsigned char)(0x80 | (u & 0x3F));
  388. sUTF8[4] = '\0';
  389. }
  390. else
  391. {
  392. sUTF8[0] = '\0';
  393. }
  394. }
  395. void buf_draw_UTF8_str_in_copy_buffer(char *framebuffer_copy, unsigned char **pUTF8,int start_x,int end_x,int start_y,int end_y,int offset_x,int font_idx)
  396. {
  397. ucs4_t u;
  398. LCD_DRAW_BUF lcd_draw_buf_external;
  399. lcd_draw_buf_external.current_x = start_x+offset_x;
  400. lcd_draw_buf_external.current_y = start_y+2;
  401. lcd_draw_buf_external.pPcfFont = &pcfFonts[font_idx - 1];
  402. lcd_draw_buf_external.screen_buf = (unsigned char*)framebuffer_copy;
  403. lcd_draw_buf_external.line_height = pcfFonts[font_idx - 1].Fmetrics.linespace + LINE_SPACE_ADDON;
  404. lcd_draw_buf_external.align_adjustment = 0;
  405. while (**pUTF8 > MAX_ESC_CHAR)
  406. {
  407. if ((u = UTF8_to_UCS4((unsigned char**)pUTF8)))
  408. {
  409. buf_draw_char_external(&lcd_draw_buf_external,u,start_x,end_x,start_y,end_y);
  410. }
  411. }
  412. }
  413. void buf_draw_UTF8_str(unsigned char **pUTF8)
  414. {
  415. #ifndef WIKIPCF
  416. unsigned char c, c2;
  417. char c3;
  418. long v_line_bottom;
  419. ucs4_t u;
  420. int font_idx;
  421. int nWidth;
  422. int nHeight;
  423. int nBytes;
  424. int nImageY;
  425. int i, j;
  426. int nByteIdx, nBitIdx;
  427. if (NULL == pUTF8 || NULL == *pUTF8) {
  428. return;
  429. }
  430. c = **pUTF8;
  431. if (c <= MAX_ESC_CHAR)
  432. {
  433. (*pUTF8)++;
  434. switch(c)
  435. {
  436. case ESC_0_SPACE_LINE: /* space line */
  437. c2 = **pUTF8;
  438. (*pUTF8)++;
  439. lcd_draw_buf.current_x = 0;
  440. lcd_draw_buf.current_y += lcd_draw_buf.actual_height;
  441. lcd_draw_buf.line_height = c2;
  442. lcd_draw_buf.actual_height = lcd_draw_buf.line_height;
  443. lcd_draw_buf.align_adjustment = 0;
  444. if (lcd_draw_buf.current_y + lcd_draw_buf.line_height >= LCD_BUF_HEIGHT_PIXELS)
  445. lcd_draw_buf.current_y = LCD_BUF_HEIGHT_PIXELS - lcd_draw_buf.line_height - 1;
  446. draw_article_positioner(lcd_draw_buf.current_y);
  447. break;
  448. case ESC_1_NEW_LINE_DEFAULT_FONT: /* new line with default font and line space */
  449. lcd_draw_buf.current_x = 0;
  450. lcd_draw_buf.current_y += lcd_draw_buf.actual_height;
  451. lcd_draw_buf.pPcfFont = &pcfFonts[DEFAULT_FONT_IDX - 1];
  452. lcd_draw_buf.line_height = pcfFonts[DEFAULT_FONT_IDX - 1].Fmetrics.linespace + LINE_SPACE_ADDON;
  453. lcd_draw_buf.actual_height = lcd_draw_buf.line_height;
  454. lcd_draw_buf.align_adjustment = 0;
  455. if (lcd_draw_buf.current_y + lcd_draw_buf.line_height >= LCD_BUF_HEIGHT_PIXELS)
  456. lcd_draw_buf.current_y = LCD_BUF_HEIGHT_PIXELS - lcd_draw_buf.line_height - 1;
  457. draw_article_positioner(lcd_draw_buf.current_y);
  458. break;
  459. case ESC_2_NEW_LINE_SAME_FONT: /* new line with previous font and line space */
  460. lcd_draw_buf.current_x = 0;
  461. lcd_draw_buf.current_y += lcd_draw_buf.actual_height;
  462. lcd_draw_buf.actual_height = lcd_draw_buf.line_height;
  463. lcd_draw_buf.align_adjustment = 0;
  464. if (lcd_draw_buf.current_y + lcd_draw_buf.line_height >= LCD_BUF_HEIGHT_PIXELS)
  465. lcd_draw_buf.current_y = LCD_BUF_HEIGHT_PIXELS - lcd_draw_buf.line_height - 1;
  466. draw_article_positioner(lcd_draw_buf.current_y);
  467. break;
  468. case ESC_3_NEW_LINE_WITH_FONT: /* new line with specified font and line space */
  469. c2 = **pUTF8;
  470. (*pUTF8)++;
  471. lcd_draw_buf.current_x = 0;
  472. lcd_draw_buf.current_y += lcd_draw_buf.actual_height;
  473. font_idx = c2 & 0x07;
  474. if (font_idx > FONT_COUNT)
  475. font_idx = DEFAULT_FONT_IDX;
  476. lcd_draw_buf.pPcfFont = &pcfFonts[font_idx - 1];
  477. lcd_draw_buf.line_height = c2 >> 3;
  478. lcd_draw_buf.actual_height = lcd_draw_buf.line_height;
  479. lcd_draw_buf.align_adjustment = 0;
  480. if (lcd_draw_buf.current_y + lcd_draw_buf.line_height >= LCD_BUF_HEIGHT_PIXELS)
  481. lcd_draw_buf.current_y = LCD_BUF_HEIGHT_PIXELS - lcd_draw_buf.line_height - 1;
  482. draw_article_positioner(lcd_draw_buf.current_y);
  483. break;
  484. case ESC_4_CHANGE_FONT: /* change font */
  485. c2 = **pUTF8;
  486. (*pUTF8)++;
  487. font_idx = c2 & 0x07;
  488. if (font_idx > FONT_COUNT)
  489. font_idx = DEFAULT_FONT_IDX;
  490. lcd_draw_buf.pPcfFont = &pcfFonts[font_idx - 1];
  491. lcd_draw_buf.align_adjustment = ((signed char)c2 >> 3);
  492. if (lcd_draw_buf.current_y + lcd_draw_buf.line_height + lcd_draw_buf.align_adjustment >= LCD_BUF_HEIGHT_PIXELS)
  493. lcd_draw_buf.align_adjustment = LCD_BUF_HEIGHT_PIXELS - lcd_draw_buf.line_height - lcd_draw_buf.current_y - 1;
  494. if (lcd_draw_buf.current_y + lcd_draw_buf.align_adjustment < lcd_draw_buf.line_height - 1)
  495. lcd_draw_buf.align_adjustment = lcd_draw_buf.line_height - lcd_draw_buf.current_y - 1;
  496. break;
  497. case ESC_5_RESET_TO_DEFAULT_FONT: /* reset to the default font */
  498. lcd_draw_buf.pPcfFont = &pcfFonts[DEFAULT_FONT_IDX - 1];
  499. break;
  500. case ESC_6_RESET_TO_DEFAULT_ALIGN: /* reset to the default vertical alignment */
  501. lcd_draw_buf.vertical_adjustment = 0;
  502. break;
  503. case ESC_7_FORWARD: /* forward */
  504. c2 = **pUTF8;
  505. (*pUTF8)++;
  506. lcd_draw_buf.current_x += c2;
  507. if (lcd_draw_buf.current_x > LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN - lcd_draw_buf.vertical_adjustment)
  508. lcd_draw_buf.current_x = LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN - lcd_draw_buf.vertical_adjustment;
  509. break;
  510. case ESC_8_BACKWARD: /* backward */
  511. c2 = **pUTF8;
  512. (*pUTF8)++;
  513. if (lcd_draw_buf.current_x < c2)
  514. lcd_draw_buf.current_x = 0;
  515. else
  516. lcd_draw_buf.current_x -= c2;
  517. break;
  518. case ESC_9_ALIGN_ADJUSTMENT: /* vertical alignment adjustment */
  519. c3 = **pUTF8;
  520. (*pUTF8)++;
  521. lcd_draw_buf.vertical_adjustment += c3;
  522. //if (lcd_draw_buf.current_y + lcd_draw_buf.line_height + lcd_draw_buf.align_adjustment >= LCD_BUF_HEIGHT_PIXELS)
  523. // lcd_draw_buf.align_adjustment = LCD_BUF_HEIGHT_PIXELS - lcd_draw_buf.line_height - lcd_draw_buf.current_y - 1;
  524. //if (lcd_draw_buf.current_y + lcd_draw_buf.align_adjustment < lcd_draw_buf.line_height - 1)
  525. // lcd_draw_buf.align_adjustment = lcd_draw_buf.line_height - lcd_draw_buf.current_y - 1;
  526. break;
  527. case ESC_10_HORIZONTAL_LINE: /* drawing horizontal line */
  528. c2 = **pUTF8;
  529. (*pUTF8)++;
  530. if ((long)c2 > lcd_draw_buf.current_x)
  531. c2 = (unsigned char)lcd_draw_buf.current_x;
  532. buf_draw_horizontal_line(lcd_draw_buf.current_x - (unsigned long)c2 + LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment,
  533. lcd_draw_buf.current_x + LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment);
  534. break;
  535. case ESC_11_VERTICAL_LINE: /* drawing vertical line */
  536. c2 = **pUTF8;
  537. (*pUTF8)++;
  538. v_line_bottom = lcd_draw_buf.current_y + lcd_draw_buf.line_height;
  539. v_line_bottom -= lcd_draw_buf.align_adjustment;
  540. if (v_line_bottom < 0)
  541. v_line_bottom = 0;
  542. if ((long)c2 > v_line_bottom)
  543. c2 = (unsigned char)v_line_bottom;
  544. buf_draw_vertical_line(v_line_bottom - (unsigned long)c2, v_line_bottom - 1);
  545. break;
  546. case ESC_12_FULL_HORIZONTAL_LINE: /* drawing horizontal line from left-most pixel to right-most pixel */
  547. lcd_draw_buf.current_x = 0;
  548. lcd_draw_buf.current_y += lcd_draw_buf.actual_height;
  549. lcd_draw_buf.line_height = 1;
  550. lcd_draw_buf.actual_height = lcd_draw_buf.line_height;
  551. lcd_draw_buf.align_adjustment = 0;
  552. buf_draw_horizontal_line(LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment, LCD_BUF_WIDTH_PIXELS);
  553. break;
  554. case ESC_13_FULL_VERTICAL_LINE: /* drawing vertical line from top of the line to the bottom */
  555. lcd_draw_buf.current_x += 1;
  556. buf_draw_vertical_line(lcd_draw_buf.current_y, lcd_draw_buf.current_y + lcd_draw_buf.line_height - 1);
  557. lcd_draw_buf.current_x += 2;
  558. break;
  559. case ESC_14_BITMAP: /* bitmap */
  560. c2 = **pUTF8;
  561. (*pUTF8)++;
  562. nWidth = c2;
  563. c2 = **pUTF8;
  564. (*pUTF8)++;
  565. nHeight = c2;
  566. c2 = **pUTF8;
  567. (*pUTF8)++;
  568. nHeight |= c2 << 8;
  569. if (lcd_draw_buf.current_x == 0)
  570. lcd_draw_buf.current_x = LCD_EXTRA_LEFT_MARGIN_FOR_IMAGE;
  571. else
  572. lcd_draw_buf.current_x++;
  573. if (lcd_draw_buf.line_height < nHeight + 1)
  574. lcd_draw_buf.actual_height = nHeight + 3;
  575. nImageY = lcd_draw_buf.current_y + 3;
  576. if ((lcd_draw_buf.current_x + LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment) % 8 == 0)
  577. {
  578. nBytes = (nWidth + 7) / 8;
  579. if (nBytes > LCD_BUF_WIDTH_BYTES - 1)
  580. nBytes = LCD_BUF_WIDTH_BYTES - 1;
  581. nByteIdx = (lcd_draw_buf.current_x + LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment) / 8;
  582. for (i = 0; i < nHeight; i++)
  583. {
  584. memcpy(&lcd_draw_buf.screen_buf[nImageY * LCD_BUF_WIDTH_BYTES + nByteIdx], *pUTF8, nBytes);
  585. *pUTF8 += (nWidth + 7) / 8;
  586. nImageY++;
  587. }
  588. }
  589. else
  590. {
  591. for (i = 0; i < nHeight; i++)
  592. {
  593. for(j = 0; j < nWidth; j++)
  594. {
  595. nByteIdx = j / 8;
  596. nBitIdx = 7 - (j % 8);
  597. if ((*pUTF8)[nByteIdx] & (1 << nBitIdx))
  598. {
  599. lcd_set_pixel(lcd_draw_buf.screen_buf, lcd_draw_buf.current_x +
  600. LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment + j, nImageY);
  601. }
  602. }
  603. *pUTF8 += (nWidth + 7) / 8;
  604. nImageY++;
  605. }
  606. }
  607. lcd_draw_buf.current_x += nWidth;
  608. break;
  609. default:
  610. break;
  611. }
  612. }
  613. while (**pUTF8 > MAX_ESC_CHAR) /* stop at end of string or escape character */
  614. {
  615. if ((u = UTF8_to_UCS4(pUTF8)))
  616. {
  617. buf_draw_char(u);
  618. if(display_first_page==0 && lcd_draw_buf.current_y > LCD_HEIGHT_LINES + article_start_y_pos)
  619. {
  620. display_first_page = 1;
  621. lcd_draw_cur_y_pos = article_start_y_pos;
  622. finger_move_speed = 0;
  623. repaint_framebuffer(lcd_draw_buf.screen_buf, lcd_draw_cur_y_pos, 0);
  624. if (lcd_draw_init_y_pos < article_start_y_pos)
  625. lcd_draw_init_y_pos = article_start_y_pos;
  626. if (lcd_draw_init_y_pos > article_start_y_pos)
  627. {
  628. display_article_with_pcf(lcd_draw_init_y_pos);
  629. }
  630. }
  631. }
  632. }
  633. #endif
  634. }
  635. #define MAX_PIXELS_EACH_SIDE 5
  636. void draw_language_link_arrow()
  637. {
  638. int i, j;
  639. int nPixelsEachSide;
  640. if (bShowLanguageLinks)
  641. nPixelsEachSide = MAX_PIXELS_EACH_SIDE;
  642. else
  643. nPixelsEachSide = 0;
  644. for (i = LCD_TOP_MARGIN; i < LCD_TOP_MARGIN + LANGUAGE_LINK_HEIGHT; i++)
  645. {
  646. if (i == LCD_TOP_MARGIN + 1 || i == LCD_TOP_MARGIN + LANGUAGE_LINK_HEIGHT - 2)
  647. {
  648. for (j = LCD_BUF_WIDTH_PIXELS - LANGUAGE_LINK_WIDTH - LCD_LEFT_MARGIN + 2; j < LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN - 2; j++)
  649. {
  650. lcd_set_pixel(framebuffer, j, i);
  651. }
  652. }
  653. else if (1 + LCD_TOP_MARGIN < i && i < LCD_TOP_MARGIN + LANGUAGE_LINK_HEIGHT - 2)
  654. {
  655. for (j = LCD_BUF_WIDTH_PIXELS - LANGUAGE_LINK_WIDTH - LCD_LEFT_MARGIN + 1; j < LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN - 1; j++)
  656. {
  657. lcd_set_pixel(framebuffer, j, i);
  658. }
  659. }
  660. if (8 + LCD_TOP_MARGIN <= i && i <= 8 + LCD_TOP_MARGIN + MAX_PIXELS_EACH_SIDE)
  661. {
  662. if (bShowLanguageLinks)
  663. {
  664. if (nPixelsEachSide >= 0)
  665. {
  666. for (j = -nPixelsEachSide; j <= nPixelsEachSide; j++)
  667. lcd_clear_pixel(framebuffer, LCD_BUF_WIDTH_PIXELS - LANGUAGE_LINK_WIDTH - LCD_LEFT_MARGIN + 11 + j, i);
  668. nPixelsEachSide--;
  669. }
  670. }
  671. else
  672. {
  673. if (nPixelsEachSide <= MAX_PIXELS_EACH_SIDE)
  674. {
  675. for (j = -nPixelsEachSide; j <= nPixelsEachSide; j++)
  676. lcd_clear_pixel(framebuffer, LCD_BUF_WIDTH_PIXELS - LANGUAGE_LINK_WIDTH - LCD_LEFT_MARGIN + 11 + j, i);
  677. nPixelsEachSide++;
  678. }
  679. }
  680. }
  681. }
  682. }
  683. void repaint_framebuffer(unsigned char *buf, int pos, int b_repaint_invert_link)
  684. {
  685. #ifndef WIKIPCF
  686. int framebuffersize;
  687. framebuffersize = framebuffer_size();
  688. guilib_fb_lock();
  689. //guilib_clear();
  690. memcpy(framebuffer,buf+pos*LCD_VRAM_WIDTH_PIXELS/8,framebuffersize);
  691. if (display_mode == DISPLAY_MODE_ARTICLE && (language_link_count || restricted_article) && (pos == article_start_y_pos || pos == 0))
  692. {
  693. draw_language_link_arrow();
  694. }
  695. // if (b_repaint_invert_link)
  696. // repaint_invert_link();
  697. if (b_show_scroll_bar)
  698. show_scroll_bar(1);
  699. guilib_fb_unlock();
  700. #endif
  701. }
  702. void buf_draw_horizontal_line(unsigned long start_x, unsigned long end_x)
  703. {
  704. int i;
  705. long h_line_y;
  706. h_line_y = lcd_draw_buf.current_y + lcd_draw_buf.line_height;
  707. h_line_y -= lcd_draw_buf.align_adjustment + 1;
  708. if (end_x > LCD_BUF_WIDTH_PIXELS)
  709. end_x = LCD_BUF_WIDTH_PIXELS;
  710. for(i = start_x;i<end_x;i++)
  711. {
  712. lcd_set_pixel(lcd_draw_buf.screen_buf,i, h_line_y);
  713. }
  714. }
  715. void buf_draw_vertical_line(unsigned long start_y, unsigned long end_y)
  716. {
  717. unsigned long idx_in_byte;
  718. unsigned char *p;
  719. if (lcd_draw_buf.current_x + LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment < LCD_BUF_WIDTH_PIXELS)
  720. {
  721. idx_in_byte = 7 - ((lcd_draw_buf.current_x + LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment) & 0x07);
  722. p = lcd_draw_buf.screen_buf + start_y * LCD_BUF_WIDTH_BYTES + ((lcd_draw_buf.current_x + LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment)>> 3);
  723. while (start_y <= end_y)
  724. {
  725. *p |= 1 << idx_in_byte;
  726. start_y++;
  727. p += LCD_BUF_WIDTH_BYTES;
  728. }
  729. }
  730. }
  731. void lcd_set_pixel(unsigned char *membuffer,int x, int y)
  732. {
  733. unsigned int byte = (x + LCD_VRAM_WIDTH_PIXELS * y) / 8;
  734. unsigned int bit = (x + LCD_VRAM_WIDTH_PIXELS * y) % 8;
  735. membuffer[byte] |= (1 << (7 - bit));
  736. }
  737. void lcd_set_framebuffer_pixel(int x, int y)
  738. {
  739. unsigned int byte = (x + LCD_VRAM_WIDTH_PIXELS * y) / 8;
  740. unsigned int bit = (x + LCD_VRAM_WIDTH_PIXELS * y) % 8;
  741. framebuffer[byte] |= (1 << (7 - bit));
  742. }
  743. void lcd_set_framebuffer_byte(char c, int x, int y)
  744. {
  745. unsigned int byte = (x + LCD_VRAM_WIDTH_PIXELS * y) / 8;
  746. framebuffer[byte] = c;
  747. }
  748. void lcd_clear_framebuffer_pixel(int x, int y)
  749. {
  750. unsigned int byte = (x + LCD_VRAM_WIDTH_PIXELS * y) / 8;
  751. unsigned int bit = (x + LCD_VRAM_WIDTH_PIXELS * y) % 8;
  752. if (framebuffer[byte] & (1 << (7 - bit)))
  753. framebuffer[byte] ^= (1 << (7 - bit));
  754. }
  755. char lcd_draw_buf_get_byte(int x, int y)
  756. {
  757. unsigned int byte = (x + LCD_VRAM_WIDTH_PIXELS * y) / 8;
  758. return framebuffer[byte];
  759. }
  760. int lcd_draw_buf_get_pixel(int x, int y)
  761. {
  762. unsigned int byte = (x + LCD_VRAM_WIDTH_PIXELS * y) / 8;
  763. unsigned int bit = (x + LCD_VRAM_WIDTH_PIXELS * y) % 8;
  764. if (lcd_draw_buf.screen_buf[byte] & (1 << (7 - bit)))
  765. return 1;
  766. else
  767. return 0;
  768. }
  769. void lcd_clear_pixel(unsigned char *membuffer,int x, int y)
  770. {
  771. unsigned int byte = (x + LCD_VRAM_WIDTH_PIXELS * y) / 8;
  772. unsigned int bit = (x + LCD_VRAM_WIDTH_PIXELS * y) % 8;
  773. membuffer[byte] &= ~(1 << (7 - bit));
  774. }
  775. void buf_draw_char(ucs4_t u)
  776. {
  777. bmf_bm_t *bitmap;
  778. charmetric_bmf Cmetrics;
  779. int bytes_to_process;
  780. int x_base;
  781. int y_base;
  782. int x_offset;
  783. int y_offset;
  784. int x_bit_idx;
  785. int i; // bitmap byte index
  786. int j; // bitmap bit index
  787. unsigned char *p; // pointer to lcd draw buffer
  788. if(pres_bmfbm(u, lcd_draw_buf.pPcfFont, &bitmap, &Cmetrics)<0)
  789. {
  790. return;
  791. }
  792. if(u==32)
  793. {
  794. lcd_draw_buf.current_x += Cmetrics.widthDevice;
  795. return;
  796. }
  797. if (bitmap == NULL)
  798. return;
  799. bytes_to_process = Cmetrics.widthBytes * Cmetrics.height;
  800. x_base = lcd_draw_buf.current_x + Cmetrics.LSBearing + LCD_LEFT_MARGIN + lcd_draw_buf.vertical_adjustment;
  801. if (x_base < LCD_BUF_WIDTH_PIXELS)
  802. { // only draw the chracter if there is space left before the right margin of the LCD screen
  803. y_base = lcd_draw_buf.current_y + lcd_draw_buf.align_adjustment;
  804. x_offset = 0;
  805. y_offset = lcd_draw_buf.line_height - (lcd_draw_buf.pPcfFont->Fmetrics.descent + Cmetrics.ascent);
  806. x_bit_idx = x_base & 0x07;
  807. //p = lcd_draw_buf.screen_buf + (y_base + y_offset) * LCD_BUF_WIDTH_BYTES + (x_base >> 3);
  808. for (i = 0; i < bytes_to_process; i++)
  809. {
  810. j = 7;
  811. while (j >= 0)
  812. {
  813. if (x_offset >= Cmetrics.widthBits)
  814. {
  815. x_offset = 0;
  816. y_offset++;
  817. p = lcd_draw_buf.screen_buf + (y_base + y_offset) * LCD_BUF_WIDTH_BYTES + x_base;
  818. }
  819. if (x_offset < Cmetrics.width)
  820. {
  821. if ((bitmap[i] & (1 << j)) && x_base + x_offset < LCD_BUF_WIDTH_PIXELS)
  822. {
  823. //*p |= 1 << ((x_base + x_offset) & 0x07);
  824. lcd_set_pixel(lcd_draw_buf.screen_buf,x_base + x_offset, y_base+y_offset);
  825. }
  826. }
  827. x_offset++;
  828. x_bit_idx++;
  829. if (!(x_bit_idx & 0x07))
  830. {
  831. x_bit_idx = 0;
  832. p++;
  833. }
  834. j--;
  835. }
  836. }
  837. }
  838. lcd_draw_buf.current_x += Cmetrics.widthDevice;
  839. }
  840. int get_external_str_pixel_width(unsigned char *pIn, int font_idx)
  841. {
  842. bmf_bm_t *bitmap;
  843. charmetric_bmf Cmetrics;
  844. int width = 0;
  845. ucs4_t u;
  846. unsigned char **pUTF8 = &pIn;
  847. while (**pUTF8 > MAX_ESC_CHAR)
  848. {
  849. if ((u = UTF8_to_UCS4((unsigned char**)pUTF8)))
  850. {
  851. pres_bmfbm(u, &pcfFonts[font_idx - 1], &bitmap, &Cmetrics);
  852. if (bitmap != NULL)
  853. width += Cmetrics.widthDevice;
  854. }
  855. }
  856. return width;
  857. }
  858. void buf_draw_char_external(LCD_DRAW_BUF *lcd_draw_buf_external,ucs4_t u,int start_x,int end_x,int start_y,int end_y)
  859. {
  860. bmf_bm_t *bitmap;
  861. charmetric_bmf Cmetrics;
  862. int bytes_to_process;
  863. int x_base;
  864. int y_base;
  865. int x_offset;
  866. int y_offset;
  867. int x_bit_idx;
  868. int i; // bitmap byte index
  869. int j; // bitmap bit index
  870. unsigned char *p; // pointer to lcd draw buffer
  871. if(pres_bmfbm(u, lcd_draw_buf_external->pPcfFont, &bitmap, &Cmetrics)<0)
  872. return;
  873. if(u==32)
  874. {
  875. lcd_draw_buf_external->current_x += Cmetrics.widthDevice;
  876. return;
  877. }
  878. if (bitmap == NULL)
  879. return;
  880. bytes_to_process = Cmetrics.widthBytes * Cmetrics.height;
  881. x_base = lcd_draw_buf_external->current_x + Cmetrics.LSBearing;
  882. if((x_base + Cmetrics.widthDevice) > end_x)
  883. {
  884. lcd_draw_buf_external->current_x = start_x+2;
  885. x_base = 0;
  886. lcd_draw_buf_external->current_y+=lcd_draw_buf_external->line_height;
  887. }
  888. y_base = lcd_draw_buf_external->current_y + lcd_draw_buf_external->align_adjustment;
  889. x_offset = 0;
  890. y_offset = lcd_draw_buf_external->line_height - (lcd_draw_buf_external->pPcfFont->Fmetrics.descent + Cmetrics.ascent);
  891. x_bit_idx = x_base & 0x07;
  892. for (i = 0; i < bytes_to_process; i++)
  893. {
  894. j = 7;
  895. while (j >= 0)
  896. {
  897. if (x_offset >= Cmetrics.widthBits)
  898. {
  899. x_offset = 0;
  900. y_offset++;
  901. }
  902. if (x_offset < Cmetrics.width)
  903. {
  904. if (bitmap[i] & (1 << j))
  905. {
  906. lcd_set_pixel(lcd_draw_buf_external->screen_buf,x_base + x_offset, y_base+y_offset);
  907. }
  908. }
  909. x_offset++;
  910. x_bit_idx++;
  911. if (!(x_bit_idx & 0x07))
  912. {
  913. x_bit_idx = 0;
  914. p++;
  915. }
  916. j--;
  917. }
  918. }
  919. lcd_draw_buf_external->current_x += Cmetrics.widthDevice;
  920. }
  921. int get_UTF8_char_width(int idxFont, char **pContent, long *lenContent, int *nCharBytes)
  922. {
  923. ucs4_t u;
  924. char *pBase;
  925. charmetric_bmf Cmetrics;
  926. bmf_bm_t *bitmap;
  927. pBase = *pContent;
  928. u = UTF8_to_UCS4((unsigned char **)pContent);
  929. *nCharBytes = *pContent - pBase;
  930. *lenContent -= *nCharBytes;
  931. pres_bmfbm(u, &pcfFonts[idxFont - 1], &bitmap, &Cmetrics);
  932. if (bitmap == NULL)
  933. return 0;
  934. else
  935. return Cmetrics.widthDevice;
  936. }
  937. bool is_word_break(ucs4_t u)
  938. {
  939. unsigned char c = u & 0x000000FF;
  940. return ((u > 0x47F) || (u < 0x100 && strchr(" ~!@#$%^&*()-_+=[]\{}|;;':\",./", c)));
  941. }
  942. int extract_str_fitting_width(unsigned char **pIn, char *pOut, int max_width, int font_idx)
  943. {
  944. bmf_bm_t *bitmap;
  945. charmetric_bmf Cmetrics;
  946. int width = 0;
  947. int widthFitted = 0;
  948. ucs4_t u;
  949. unsigned char *pOrigIn;
  950. int nBytesFittingWidth = 0;
  951. int nLastBytes, nLastWidth;
  952. pOrigIn = *pIn;
  953. pOut[0] = '\0';
  954. while (**pIn > MAX_ESC_CHAR && width <= max_width)
  955. {
  956. nLastBytes = *pIn - pOrigIn;
  957. nLastWidth = width;
  958. if ((u = UTF8_to_UCS4((unsigned char**)(pIn))))
  959. {
  960. pres_bmfbm(u, &pcfFonts[font_idx - 1], &bitmap, &Cmetrics);
  961. if (bitmap != NULL)
  962. width += Cmetrics.widthDevice;
  963. if (is_word_break(u))
  964. {
  965. if (width > max_width)
  966. {
  967. nBytesFittingWidth = nLastBytes;
  968. widthFitted = nLastWidth;
  969. }
  970. else
  971. {
  972. nBytesFittingWidth = *pIn - pOrigIn;
  973. widthFitted = width;
  974. }
  975. }
  976. }
  977. }
  978. if (width > max_width)
  979. {
  980. memcpy(pOut, pOrigIn, nBytesFittingWidth);
  981. pOut[nBytesFittingWidth] = '\0';
  982. *pIn = pOrigIn + nBytesFittingWidth;
  983. }
  984. else
  985. {
  986. strcpy(pOut, pOrigIn);
  987. widthFitted = width;
  988. }
  989. return widthFitted;
  990. }
  991. #ifndef WIKIPCF
  992. void init_render_article(long init_y_pos)
  993. {
  994. //if(lcd_draw_buf.current_y>0)
  995. // memset(lcd_draw_buf.screen_buf,0,lcd_draw_buf.current_y*LCD_VRAM_WIDTH_PIXELS/8);
  996. if (lcd_draw_buf.screen_buf)
  997. memset(lcd_draw_buf.screen_buf, 0, LCD_BUF_WIDTH_BYTES * LCD_BUF_HEIGHT_PIXELS);
  998. article_buf_pointer = NULL;
  999. lcd_draw_buf.current_x = 0;
  1000. lcd_draw_buf.current_y = 0;
  1001. lcd_draw_buf.drawing = 0;
  1002. lcd_draw_buf.pPcfFont = NULL;
  1003. lcd_draw_buf.line_height = 0;
  1004. lcd_draw_buf.actual_height = 0;
  1005. lcd_draw_buf.align_adjustment = 0;
  1006. lcd_draw_buf.vertical_adjustment = 0;
  1007. display_first_page = 0;
  1008. lcd_draw_cur_y_pos = 0;
  1009. article_start_y_pos = 0;
  1010. bShowLanguageLinks = 0;
  1011. lcd_draw_init_y_pos = init_y_pos;
  1012. finger_move_speed = 0;
  1013. lcd_draw_buf_pos = 0;
  1014. }
  1015. #endif
  1016. void render_wikipedia_license_text(void)
  1017. {
  1018. #ifndef WIKIPCF
  1019. long start_x, start_y, end_x, end_y;
  1020. WIKI_LICENSE_DRAW *license_draw;
  1021. int draw_lines;
  1022. int i;
  1023. license_draw = wiki_license_draw();
  1024. lcd_draw_buf.current_y += SPACE_BEFORE_LICENSE_TEXT;
  1025. if (license_draw->lines < LCD_BUF_HEIGHT_PIXELS - lcd_draw_buf.current_y)
  1026. draw_lines = license_draw->lines;
  1027. else
  1028. draw_lines = LCD_BUF_HEIGHT_PIXELS - lcd_draw_buf.current_y;
  1029. memcpy(&lcd_draw_buf.screen_buf[lcd_draw_buf.current_y * LCD_BUF_WIDTH_BYTES], license_draw->buf, draw_lines * LCD_BUF_WIDTH_BYTES);
  1030. for (i = 0; i < license_draw->link_count; i++)
  1031. {
  1032. start_x = license_draw->links[i].start_xy & 0xFF;
  1033. start_y = (license_draw->links[i].start_xy >> 8) + lcd_draw_buf.current_y;
  1034. end_x = license_draw->links[i].end_xy & 0xFF;
  1035. end_y = (license_draw->links[i].end_xy >> 8) + lcd_draw_buf.current_y;
  1036. articleLink[article_link_count].start_xy = license_draw->links[i].start_xy;
  1037. articleLink[article_link_count].end_xy = license_draw->links[i].start_xy;
  1038. articleLink[article_link_count].start_xy = (unsigned long)(start_x | (start_y << 8));
  1039. articleLink[article_link_count].end_xy = (unsigned long)(end_x | (end_y << 8));
  1040. articleLink[article_link_count++].article_id = license_draw->links[i].article_id;
  1041. }
  1042. lcd_draw_buf.current_y += draw_lines;
  1043. if (lcd_draw_buf.current_y > LCD_BUF_HEIGHT_PIXELS)
  1044. lcd_draw_buf.current_y = LCD_BUF_HEIGHT_PIXELS;
  1045. #endif
  1046. }
  1047. int render_article_with_pcf()
  1048. {
  1049. if (!article_buf_pointer)
  1050. return 0;
  1051. buf_draw_UTF8_str(&article_buf_pointer);
  1052. if(stop_render_article == 1 && display_first_page == 1)
  1053. {
  1054. article_buf_pointer = NULL;
  1055. stop_render_article = 0;
  1056. return 0;
  1057. }
  1058. if(request_display_next_page > 0 && lcd_draw_buf.current_y > request_y_pos)
  1059. {
  1060. lcd_draw_cur_y_pos = request_y_pos - LCD_HEIGHT_LINES;
  1061. if (bShowLanguageLinks)
  1062. {
  1063. if (lcd_draw_cur_y_pos < 0)
  1064. {
  1065. lcd_draw_cur_y_pos = 0;
  1066. }
  1067. else if (lcd_draw_cur_y_pos >= article_start_y_pos)
  1068. bShowLanguageLinks = 0;
  1069. }
  1070. else
  1071. {
  1072. if (lcd_draw_cur_y_pos < article_start_y_pos)
  1073. {
  1074. lcd_draw_cur_y_pos = article_start_y_pos;
  1075. }
  1076. }
  1077. repaint_framebuffer(lcd_draw_buf.screen_buf, lcd_draw_cur_y_pos, 1);
  1078. request_display_next_page = 0;
  1079. }
  1080. if(!*article_buf_pointer)
  1081. {
  1082. render_wikipedia_license_text();
  1083. if(display_first_page == 0 || request_display_next_page > 0)
  1084. {
  1085. if(request_display_next_page > 0)
  1086. {
  1087. lcd_draw_cur_y_pos = request_y_pos - LCD_HEIGHT_LINES;
  1088. if (lcd_draw_cur_y_pos + LCD_HEIGHT_LINES > lcd_draw_buf.current_y)
  1089. {
  1090. lcd_draw_cur_y_pos = lcd_draw_buf.current_y - LCD_HEIGHT_LINES;
  1091. }
  1092. if (bShowLanguageLinks)
  1093. {
  1094. if (lcd_draw_cur_y_pos < 0)
  1095. {
  1096. lcd_draw_cur_y_pos = 0;
  1097. }
  1098. else if (lcd_draw_cur_y_pos >= article_start_y_pos)
  1099. bShowLanguageLinks = 0;
  1100. }
  1101. else
  1102. {
  1103. if (lcd_draw_cur_y_pos < article_start_y_pos)
  1104. {
  1105. lcd_draw_cur_y_pos = article_start_y_pos;
  1106. }
  1107. }
  1108. }
  1109. else if(display_first_page==0 && lcd_draw_cur_y_pos < article_start_y_pos)
  1110. lcd_draw_cur_y_pos = article_start_y_pos;
  1111. repaint_framebuffer(lcd_draw_buf.screen_buf, lcd_draw_cur_y_pos, 1);
  1112. display_first_page = 1;
  1113. request_display_next_page = 0;
  1114. }
  1115. article_buf_pointer = NULL;
  1116. return 0;
  1117. }
  1118. return 1;
  1119. }
  1120. #ifndef WIKIPCF
  1121. extern int nWikiCount;
  1122. extern int rendered_wiki_selection_count;
  1123. int render_wiki_selection_with_pcf()
  1124. {
  1125. int rc = 0;
  1126. int start_x, end_x, start_y, end_y;
  1127. if (rendered_wiki_selection_count < 0)
  1128. return rc;
  1129. guilib_fb_lock();
  1130. if (rendered_wiki_selection_count == 0)
  1131. {
  1132. init_render_article(0);
  1133. lcd_draw_buf.pPcfFont = &pcfFonts[SEARCH_HEADING_FONT_IDX - 1];
  1134. lcd_draw_buf.line_height = pcfFonts[SEARCH_HEADING_FONT_IDX - 1].Fmetrics.linespace;
  1135. lcd_draw_buf.current_x = 0;
  1136. lcd_draw_buf.current_y = LCD_TOP_MARGIN;
  1137. lcd_draw_buf.vertical_adjustment = 0;
  1138. lcd_draw_buf.align_adjustment = 0;
  1139. draw_string(get_nls_text("select_wiki"));
  1140. lcd_draw_buf.pPcfFont = &pcfFonts[SEARCH_LIST_FONT_IDX - 1];
  1141. lcd_draw_buf.line_height = HISTORY_RESULT_HEIGHT;
  1142. lcd_draw_buf.current_x = 0;
  1143. lcd_draw_buf.current_y = HISTORY_RESULT_START;
  1144. article_link_count = 0;
  1145. language_link_count = 0;
  1146. }
  1147. if (rendered_wiki_selection_count < nWikiCount) {
  1148. start_x = 0;
  1149. end_x = LCD_BUF_WIDTH_PIXELS - 1;
  1150. if (article_link_count < MAX_RESULT_LIST)
  1151. {
  1152. start_y = lcd_draw_buf.current_y + 1;
  1153. end_y = lcd_draw_buf.current_y + lcd_draw_buf.line_height;
  1154. articleLink[article_link_count].start_xy = (unsigned long)(start_x | (start_y << 8));
  1155. articleLink[article_link_count].end_xy = (unsigned long)(end_x | (end_y << 8));
  1156. articleLink[article_link_count++].article_id = rendered_wiki_selection_count;
  1157. }
  1158. draw_string(get_wiki_name(rendered_wiki_selection_count));
  1159. rendered_wiki_selection_count++;
  1160. lcd_draw_buf.current_x = 0;
  1161. lcd_draw_buf.current_y += lcd_draw_buf.line_height;
  1162. if (rendered_wiki_selection_count < nWikiCount)
  1163. rc = 1;
  1164. else
  1165. {
  1166. rendered_wiki_selection_count = -1;
  1167. if(display_first_page == 0)
  1168. {
  1169. repaint_framebuffer(lcd_draw_buf.screen_buf,0, 0);
  1170. display_first_page = 1;
  1171. }
  1172. else if (request_display_next_page > 0)
  1173. {
  1174. long y_pos = lcd_draw_buf.current_y - LCD_HEIGHT_LINES;
  1175. if (y_pos < 0)
  1176. y_pos = 0;
  1177. lcd_draw_cur_y_pos = y_pos;
  1178. repaint_framebuffer(lcd_draw_buf.screen_buf, lcd_draw_cur_y_pos, 1);
  1179. request_display_next_page = 0;
  1180. }
  1181. }
  1182. if(stop_render_article == 1 && display_first_page == 1)
  1183. {
  1184. rendered_wiki_selection_count = -1;
  1185. stop_render_article = 0;
  1186. }
  1187. if(request_display_next_page > 0 && lcd_draw_buf.current_y >= request_y_pos+LCD_HEIGHT_LINES)
  1188. {
  1189. lcd_draw_cur_y_pos = request_y_pos;
  1190. repaint_framebuffer(lcd_draw_buf.screen_buf,lcd_draw_cur_y_pos, 1);
  1191. request_display_next_page = 0;
  1192. }
  1193. }
  1194. guilib_fb_unlock();
  1195. return rc;
  1196. }
  1197. extern int history_count;
  1198. extern int rendered_history_count;
  1199. extern HISTORY history_list[MAX_HISTORY];
  1200. int render_history_with_pcf()
  1201. {
  1202. int rc = 0;
  1203. int start_x, end_x, start_y, end_y;
  1204. restricted_article = 0;
  1205. if (rendered_history_count < 0)
  1206. return rc;
  1207. guilib_fb_lock();
  1208. if (rendered_history_count == 0)
  1209. {
  1210. init_render_article(0);
  1211. lcd_draw_buf.pPcfFont = &pcfFonts[SEARCH_HEADING_FONT_IDX - 1];
  1212. lcd_draw_buf.line_height = pcfFonts[SEARCH_HEADING_FONT_IDX - 1].Fmetrics.linespace;
  1213. lcd_draw_buf.current_x = 0;
  1214. lcd_draw_buf.current_y = LCD_TOP_MARGIN;
  1215. lcd_draw_buf.vertical_adjustment = 0;
  1216. lcd_draw_buf.align_adjustment = 0;
  1217. draw_string(get_nls_text("history_title"));
  1218. lcd_draw_buf.pPcfFont = &pcfFonts[SEARCH_LIST_FONT_IDX - 1];
  1219. lcd_draw_buf.line_height = HISTORY_RESULT_HEIGHT;
  1220. lcd_draw_buf.current_x = 0;
  1221. lcd_draw_buf.current_y = HISTORY_RESULT_START;
  1222. article_link_count = 0;
  1223. language_link_count = 0;
  1224. }
  1225. if (history_count == 0) {
  1226. unsigned char *p = get_nls_text("no_history");
  1227. int str_width = get_external_str_pixel_width(p, DEFAULT_FONT_IDX);
  1228. lcd_draw_buf.current_x = (LCD_BUF_WIDTH_PIXELS - str_width) / 2;
  1229. lcd_draw_buf.current_y = 95;
  1230. lcd_draw_buf.pPcfFont = &pcfFonts[SEARCH_LIST_FONT_IDX - 1];
  1231. lcd_draw_buf.line_height = pcfFonts[SEARCH_LIST_FONT_IDX - 1].Fmetrics.linespace;
  1232. draw_string(get_nls_text("no_history"));
  1233. rendered_history_count = -1;
  1234. repaint_framebuffer(lcd_draw_buf.screen_buf,0, 0);
  1235. display_first_page = 1;
  1236. } else if (rendered_history_count < history_count) {
  1237. start_x = 0;
  1238. end_x = LCD_BUF_WIDTH_PIXELS - 1;
  1239. if (article_link_count < MAX_RESULT_LIST)
  1240. {
  1241. start_y = lcd_draw_buf.current_y + 1;
  1242. end_y = lcd_draw_buf.current_y + lcd_draw_buf.line_height;
  1243. articleLink[article_link_count].start_xy = (unsigned long)(start_x | (start_y << 8));
  1244. articleLink[article_link_count].end_xy = (unsigned long)(end_x | (end_y << 8));
  1245. articleLink[article_link_count++].article_id = history_list[rendered_history_count].idx_article;
  1246. }
  1247. draw_string(history_list[rendered_history_count].title);
  1248. rendered_history_count++;
  1249. lcd_draw_buf.current_x = 0;
  1250. lcd_draw_buf.current_y += lcd_draw_buf.line_height;
  1251. if (rendered_history_count < history_count)
  1252. rc = 1;
  1253. else
  1254. {
  1255. rendered_history_count = -1;
  1256. if(display_first_page == 0)
  1257. {
  1258. repaint_framebuffer(lcd_draw_buf.screen_buf,0, 0);
  1259. display_first_page = 1;
  1260. }
  1261. else if (request_display_next_page > 0)
  1262. {
  1263. long y_pos = lcd_draw_buf.current_y - LCD_HEIGHT_LINES;
  1264. if (y_pos < 0)
  1265. y_pos = 0;
  1266. lcd_draw_cur_y_pos = y_pos;
  1267. repaint_framebuffer(lcd_draw_buf.screen_buf, lcd_draw_cur_y_pos, 1);
  1268. request_display_next_page = 0;
  1269. }
  1270. }
  1271. if(stop_render_article == 1 && display_first_page == 1)
  1272. {
  1273. rendered_history_count = -1;
  1274. stop_render_article = 0;
  1275. }
  1276. if(request_display_next_page > 0 && lcd_draw_buf.current_y >= request_y_pos+LCD_HEIGHT_LINES)
  1277. {
  1278. lcd_draw_cur_y_pos = request_y_pos;
  1279. repaint_framebuffer(lcd_draw_buf.screen_buf,lcd_draw_cur_y_pos, 1);
  1280. request_display_next_page = 0;
  1281. }
  1282. }
  1283. guilib_fb_unlock();
  1284. return rc;
  1285. }
  1286. extern int more_search_results;
  1287. void restore_search_list_page(void)
  1288. {
  1289. if (article_link_count > NUMBER_OF_FIRST_PAGE_RESULTS)
  1290. {
  1291. more_search_results = 0;
  1292. article_link_count = NUMBER_OF_FIRST_PAGE_RESULTS;
  1293. memcpy(framebuffer, lcd_draw_buf.screen_buf, framebuffer_size()); // copy from the LCD frame buffer (for the first page)
  1294. }
  1295. }
  1296. int render_search_result_with_pcf(void)
  1297. {
  1298. int rc = 0;
  1299. int start_x, end_x, start_y, end_y;
  1300. long idxArticle;
  1301. char sTitleActual[MAX_TITLE_ACTUAL];
  1302. static long offset_next = 0;
  1303. if (!more_search_results)
  1304. {
  1305. display_first_page = 1;
  1306. return rc;
  1307. }
  1308. guilib_fb_lock();
  1309. if (article_link_count == NUMBER_OF_FIRST_PAGE_RESULTS) // has not rendered any results beyond the first page
  1310. {
  1311. offset_next = result_list_offset_next();
  1312. init_render_article(0);
  1313. memcpy(lcd_draw_buf.screen_buf, framebuffer, framebuffer_size()); // copy from the LCD frame buffer (for the first page)
  1314. display_first_page = 1;
  1315. lcd_draw_buf.pPcfFont = &pcfFonts[SEARCH_LIST_FONT_IDX - 1];
  1316. lcd_draw_buf.line_height = RESULT_HEIGHT;
  1317. lcd_draw_buf.current_x = 0;
  1318. lcd_draw_buf.current_y = (RESULT_START - 2) + RESULT_HEIGHT * NUMBER_OF_FIRST_PAGE_RESULTS;
  1319. lcd_draw_cur_y_pos = 0;
  1320. }
  1321. if ((offset_next = result_list_next_result(offset_next, &idxArticle, sTitleActual)))
  1322. {
  1323. start_x = 0;
  1324. end_x = LCD_BUF_WIDTH_PIXELS - 1;
  1325. if (article_link_count < MAX_RESULT_LIST)
  1326. {
  1327. start_y = lcd_draw_buf.current_y + 1;
  1328. end_y = lcd_draw_buf.current_y + lcd_draw_buf.line_height;
  1329. articleLink[article_link_count].start_xy = (unsigned long)(start_x | (start_y << 8));
  1330. articleLink[article_link_count].end_xy = (unsigned long)(end_x | (end_y << 8));
  1331. articleLink[article_link_count++].article_id = idxArticle;
  1332. draw_string(sTitleActual);
  1333. lcd_draw_buf.current_x = 0;
  1334. lcd_draw_buf.current_y += lcd_draw_buf.line_height;
  1335. rc = 1;
  1336. }
  1337. else
  1338. more_search_results = 0;
  1339. if (stop_render_article == 1)
  1340. {
  1341. more_search_results = 0;
  1342. stop_render_article = 0;
  1343. }
  1344. if(request_display_next_page > 0 && lcd_draw_buf.current_y >= request_y_pos+LCD_HEIGHT_LINES)
  1345. {
  1346. lcd_draw_cur_y_pos = request_y_pos;
  1347. repaint_framebuffer(lcd_draw_buf.screen_buf,lcd_draw_cur_y_pos, 1);
  1348. request_display_next_page = 0;
  1349. }
  1350. }
  1351. else
  1352. {
  1353. more_search_results = 0;
  1354. if (request_display_next_page > 0)
  1355. {
  1356. long y_pos = lcd_draw_buf.current_y - LCD_HEIGHT_LINES;
  1357. if (y_pos < 0)
  1358. y_pos = 0;
  1359. lcd_draw_cur_y_pos = y_pos;
  1360. repaint_framebuffer(lcd_draw_buf.screen_buf, lcd_draw_cur_y_pos, 1);
  1361. request_display_next_page = 0;
  1362. }
  1363. }
  1364. guilib_fb_unlock();
  1365. return rc;
  1366. }
  1367. void display_article_with_pcf(int y_move)
  1368. {
  1369. if(lcd_draw_buf.current_y<=LCD_HEIGHT_LINES + article_start_y_pos || request_display_next_page ||
  1370. (display_mode == DISPLAY_MODE_INDEX && article_link_count <= NUMBER_OF_FIRST_PAGE_RESULTS))
  1371. return;
  1372. if(article_buf_pointer && (lcd_draw_cur_y_pos+y_move+LCD_HEIGHT_LINES) > lcd_draw_buf.current_y)
  1373. {
  1374. request_display_next_page = 1;
  1375. request_y_pos = lcd_draw_cur_y_pos + y_move + LCD_HEIGHT_LINES;
  1376. display_str(get_nls_text("please_wait"));
  1377. return;
  1378. }
  1379. // if ((lcd_draw_cur_y_pos == 0 && start_y < 0) ||
  1380. // ((lcd_draw_cur_y_pos+LCD_HEIGHT_LINES)>lcd_draw_buf.current_y && start_y >= 0))
  1381. // {
  1382. // return;
  1383. // }
  1384. lcd_draw_cur_y_pos += y_move;
  1385. if (!bShowLanguageLinks && lcd_draw_cur_y_pos < article_start_y_pos)
  1386. lcd_draw_cur_y_pos = article_start_y_pos;
  1387. else if (bShowLanguageLinks && lcd_draw_cur_y_pos >= article_start_y_pos)
  1388. bShowLanguageLinks = 0;
  1389. if ((lcd_draw_cur_y_pos+LCD_HEIGHT_LINES)>lcd_draw_buf.current_y)
  1390. {
  1391. lcd_draw_cur_y_pos = lcd_draw_buf.current_y - LCD_HEIGHT_LINES;
  1392. }
  1393. if (lcd_draw_cur_y_pos < 0)
  1394. {
  1395. lcd_draw_cur_y_pos = 0;
  1396. }
  1397. if (display_mode == DISPLAY_MODE_ARTICLE)
  1398. {
  1399. if (lcd_draw_cur_y_pos > article_start_y_pos)
  1400. history_log_y_pos(lcd_draw_cur_y_pos - article_start_y_pos);
  1401. else
  1402. history_log_y_pos(0);
  1403. }
  1404. repaint_framebuffer(lcd_draw_buf.screen_buf, lcd_draw_cur_y_pos, 1);
  1405. display_first_page = 1;
  1406. }
  1407. float scroll_speed()
  1408. {
  1409. float speed = 0;
  1410. if (finger_move_speed)
  1411. {
  1412. if (display_mode == DISPLAY_MODE_ARTICLE)
  1413. speed = (float)finger_move_speed * ARTICLE_SCROLL_SPEED_FRICTION;
  1414. else
  1415. speed = (float)finger_move_speed * LIST_SCROLL_SPEED_FRICTION;
  1416. if (abs(speed) < 1 / SCROLL_UNIT_SECOND)
  1417. speed = 0;
  1418. }
  1419. return speed;
  1420. }
  1421. void scroll_article(void)
  1422. {
  1423. unsigned long time_now, delay_time;
  1424. if(finger_move_speed == 0)
  1425. return;
  1426. if (!display_first_page || request_display_next_page ||
  1427. ((display_mode == DISPLAY_MODE_INDEX || display_mode == DISPLAY_MODE_HISTORY || display_mode == DISPLAY_MODE_WIKI_SELECTION) &&
  1428. article_link_count <= NUMBER_OF_FIRST_PAGE_RESULTS))
  1429. {
  1430. finger_move_speed = 0;
  1431. return;
  1432. }
  1433. time_now = get_time_ticks();
  1434. delay_time = time_diff(time_now, time_scroll_article_last);
  1435. if (delay_time >= seconds_to_ticks(SCROLL_UNIT_SECOND))
  1436. {
  1437. time_scroll_article_last = time_now;
  1438. if (finger_move_speed)
  1439. {
  1440. article_scroll_increment = (float)finger_move_speed * ((float)delay_time / (float)seconds_to_ticks(1));
  1441. finger_move_speed = scroll_speed();
  1442. lcd_draw_cur_y_pos += article_scroll_increment;
  1443. if(lcd_draw_cur_y_pos < article_start_y_pos)
  1444. {
  1445. if (!bShowLanguageLinks)
  1446. lcd_draw_cur_y_pos = article_start_y_pos;
  1447. else if (lcd_draw_cur_y_pos < 0)
  1448. lcd_draw_cur_y_pos = 0;
  1449. }
  1450. else if (bShowLanguageLinks)
  1451. {
  1452. if (lcd_draw_cur_y_pos >= article_start_y_pos)
  1453. {
  1454. bShowLanguageLinks = 0;
  1455. }
  1456. }
  1457. else if (lcd_draw_cur_y_pos > lcd_draw_buf.current_y - LCD_HEIGHT_LINES)
  1458. {
  1459. lcd_draw_cur_y_pos = lcd_draw_buf.current_y - LCD_HEIGHT_LINES;
  1460. }
  1461. if (display_mode == DISPLAY_MODE_ARTICLE)
  1462. {
  1463. if (lcd_draw_cur_y_pos > article_start_y_pos)
  1464. history_log_y_pos(lcd_draw_cur_y_pos - article_start_y_pos);
  1465. else
  1466. history_log_y_pos(0);
  1467. }
  1468. }
  1469. repaint_framebuffer(lcd_draw_buf.screen_buf, lcd_draw_cur_y_pos, 1);
  1470. if (finger_move_speed == 0 && b_show_scroll_bar)
  1471. {
  1472. b_show_scroll_bar = 0;
  1473. show_scroll_bar(0); // clear scroll bar
  1474. }
  1475. }
  1476. }
  1477. void draw_icon(char *pStr)
  1478. {
  1479. int str_width;
  1480. int i, j;
  1481. str_width = get_external_str_pixel_width(pStr, SUBTITLE_FONT_IDX);
  1482. for (i = 0; i < LANGUAGE_LINK_HEIGHT; i++)
  1483. {
  1484. if (i == 1 || i == LANGUAGE_LINK_HEIGHT - 2)
  1485. {
  1486. for (j = lcd_draw_buf.current_x + LCD_LEFT_MARGIN + 1; j < lcd_draw_buf.current_x + LCD_LEFT_MARGIN + LANGUAGE_LINK_WIDTH - 2; j++)
  1487. {
  1488. lcd_set_pixel(lcd_draw_buf.screen_buf, j, lcd_draw_buf.current_y + i);
  1489. }
  1490. }
  1491. else if (1 < i && i < LANGUAGE_LINK_HEIGHT - 2)
  1492. {
  1493. for (j = lcd_draw_buf.current_x + LCD_LEFT_MARGIN; j < lcd_draw_buf.current_x + LCD_LEFT_MARGIN + LANGUAGE_LINK_WIDTH - 1; j++)
  1494. {
  1495. lcd_set_pixel(lcd_draw_buf.screen_buf, j, lcd_draw_buf.current_y + i);
  1496. }
  1497. }
  1498. }
  1499. buf_render_string(lcd_draw_buf.screen_buf, SUBTITLE_FONT_IDX, lcd_draw_buf.current_x + LCD_LEFT_MARGIN + (LANGUAGE_LINK_WIDTH - str_width - 1) / 2,
  1500. lcd_draw_buf.current_y, pStr, strlen(pStr), 1);
  1501. lcd_draw_buf.current_x += LANGUAGE_LINK_WIDTH + LANGUAGE_LINK_WIDTH_GAP;
  1502. }
  1503. void draw_restricted_mark()
  1504. {
  1505. draw_icon(get_nls_text("r"));
  1506. }
  1507. void draw_external_link(char *link_str)
  1508. {
  1509. char *pLang;
  1510. pLang = get_lang_link_display_text(link_str);
  1511. draw_icon(pLang);
  1512. }
  1513. int duplicate_wiki_lang(char *link_str1, char *link_str2)
  1514. {
  1515. char *p;
  1516. int len;
  1517. p = strchr(link_str1, ':');
  1518. if (p)
  1519. {
  1520. len = p - link_str1;
  1521. if (!memcmp(link_str1, link_str2, len))
  1522. return 1;
  1523. }
  1524. return 0;
  1525. }
  1526. void add_show_hide_language_link()
  1527. {
  1528. articleLink[1].start_xy = 0;
  1529. articleLink[1].end_xy = 0;
  1530. articleLink[1].article_id = SHOW_LANGUAGE_LINK;
  1531. externalLink[1].link_str = NULL;
  1532. articleLink[2].start_xy = 0;
  1533. articleLink[2].end_xy = 0;
  1534. articleLink[2].article_id = HIDE_LANGUAGE_LINK;
  1535. externalLink[2].link_str = NULL;
  1536. article_link_count = 3;
  1537. lcd_draw_buf.pPcfFont = &pcfFonts[DEFAULT_FONT_IDX - 1];
  1538. lcd_draw_buf.line_height = pcfFonts[DEFAULT_FONT_IDX - 1].Fmetrics.linespace;
  1539. lcd_draw_buf.current_x = 0;
  1540. lcd_draw_buf.current_y = LCD_TOP_MARGIN;
  1541. lcd_draw_buf.vertical_adjustment = 0;
  1542. lcd_draw_buf.align_adjustment = 0;
  1543. }
  1544. void display_retrieved_article(long idx_article)
  1545. {
  1546. int i;
  1547. int offset;
  1548. ARTICLE_HEADER article_header;
  1549. char title[MAX_TITLE_ACTUAL];
  1550. int bKeepPos = 0;
  1551. int nCurrentWikiId = get_wiki_id_from_idx(nCurrentWiki);
  1552. int nArticleWikiId;
  1553. int nLinkWikiId;
  1554. unsigned int start_x, end_x, start_y, end_y;
  1555. nArticleWikiId = idx_article >> 24;
  1556. if (last_display_mode == DISPLAY_MODE_HISTORY)
  1557. {
  1558. init_render_article(history_get_y_pos());
  1559. bKeepPos = 1;
  1560. }
  1561. else
  1562. {
  1563. init_render_article(0);
  1564. }
  1565. memset(articleLinkBeforeAfter, 0, sizeof(articleLinkBeforeAfter));
  1566. memcpy(&article_header,file_buffer,sizeof(ARTICLE_HEADER));
  1567. articleLink[0].start_xy = 0;
  1568. articleLink[0].end_xy = 0;
  1569. articleLink[0].article_id = PREVIOUS_ARTICLE_LINK;
  1570. externalLink[0].link_str = NULL;
  1571. article_link_count = 1;
  1572. language_link_count = 0;
  1573. if (restricted_article)
  1574. {
  1575. add_show_hide_language_link();
  1576. lcd_draw_buf.pPcfFont = &pcfFonts[DEFAULT_FONT_IDX - 1];
  1577. lcd_draw_buf.line_height = pcfFonts[DEFAULT_FONT_IDX - 1].Fmetrics.linespace;
  1578. lcd_draw_buf.current_x = 0;
  1579. lcd_draw_buf.current_y = LCD_TOP_MARGIN;
  1580. lcd_draw_buf.vertical_adjustment = 0;
  1581. lcd_draw_buf.align_adjustment = 0;
  1582. start_x = lcd_draw_buf.current_x;
  1583. start_y = lcd_draw_buf.current_y;
  1584. end_x = lcd_draw_buf.current_x + LANGUAGE_LINK_WIDTH - 1;
  1585. end_y = lcd_draw_buf.current_y + LANGUAGE_LINK_HEIGHT - 1;
  1586. draw_restricted_mark();
  1587. articleLink[article_link_count].start_xy = (unsigned long)(start_x | (start_y << 8));
  1588. articleLink[article_link_count].end_xy = (unsigned long)(end_x | (end_y << 8));
  1589. articleLink[article_link_count].article_id = RESTRICTED_MARK_LINK;
  1590. article_link_count++;
  1591. }
  1592. offset = sizeof(ARTICLE_HEADER) + sizeof(ARTICLE_LINK) * article_header.article_link_count;
  1593. // externalLink[] is for storing the pointer to the language link string.
  1594. // A corresponding artileLink (with the same index) will be used to store the start_xy and end_xy information.
  1595. // The corresponding articleLink.article_id will be set to EXTERNAL_ARTICLE_LINK for distinguishing with normal article links.
  1596. while (offset < article_header.offset_article && article_link_count < MAX_EXTERNAL_LINKS)
  1597. {
  1598. char *link_str;
  1599. link_str = file_buffer + offset;
  1600. if (wiki_lang_exist(link_str))
  1601. {
  1602. int bDuplicated = 0;
  1603. for (i = 1; i < article_link_count; i++)
  1604. {
  1605. if (externalLink[i].link_str && duplicate_wiki_lang(link_str, externalLink[i].link_str))
  1606. {
  1607. externalLink[i].link_str = link_str;
  1608. bDuplicated = 1;
  1609. }
  1610. }
  1611. if (!bDuplicated)
  1612. {
  1613. if (article_link_count == 1) // add_show_hide_language_link() has not been called yet
  1614. {
  1615. add_show_hide_language_link();
  1616. }
  1617. if (lcd_draw_buf.current_x + LCD_LEFT_MARGIN + 2 * LANGUAGE_LINK_WIDTH + 2 * LANGUAGE_LINK_WIDTH_GAP >= LCD_BUF_WIDTH_PIXELS)
  1618. {
  1619. lcd_draw_buf.current_x = 0;
  1620. lcd_draw_buf.current_y += LANGUAGE_LINK_HEIGHT + LANGUAGE_LINK_WIDTH_GAP;
  1621. }
  1622. start_x = lcd_draw_buf.current_x;
  1623. start_y = lcd_draw_buf.current_y;
  1624. end_x = lcd_draw_buf.current_x + LANGUAGE_LINK_WIDTH - 1;
  1625. end_y = lcd_draw_buf.current_y + LANGUAGE_LINK_HEIGHT - 1;
  1626. externalLink[article_link_count].link_str = link_str;
  1627. draw_external_link(externalLink[article_link_count].link_str);
  1628. articleLink[article_link_count].start_xy = (unsigned long)(start_x | (start_y << 8));
  1629. articleLink[article_link_count].end_xy = (unsigned long)(end_x | (end_y << 8));
  1630. articleLink[article_link_count].article_id = EXTERNAL_ARTICLE_LINK;
  1631. article_link_count++;
  1632. language_link_count++;
  1633. }
  1634. }
  1635. offset += strlen(file_buffer + offset) + 1;
  1636. }
  1637. if (article_link_count > 1)
  1638. {
  1639. lcd_draw_buf.current_x = 0;
  1640. lcd_draw_buf.current_y += LANGUAGE_LINK_HEIGHT + LANGUAGE_LINK_WIDTH_GAP;
  1641. }
  1642. article_start_y_pos = lcd_draw_buf.current_y;
  1643. draw_article_positioner(0);
  1644. if (lcd_draw_init_y_pos < article_start_y_pos)
  1645. lcd_draw_init_y_pos = article_start_y_pos;
  1646. if(article_header.article_link_count > MAX_ARTICLE_LINKS - article_link_count)
  1647. article_header.article_link_count = MAX_ARTICLE_LINKS - article_link_count;
  1648. offset = sizeof(ARTICLE_HEADER);
  1649. for(i = 0; i < article_header.article_link_count && article_link_count < MAX_ARTICLE_LINKS; i++)
  1650. {
  1651. memcpy(&articleLink[article_link_count],file_buffer+offset,sizeof(ARTICLE_LINK));
  1652. nLinkWikiId = articleLink[article_link_count].article_id >> 24;
  1653. if (((!nArticleWikiId || nArticleWikiId == nCurrentWikiId || get_wiki_idx_from_id(nArticleWikiId) >= 0) && !nLinkWikiId) ||
  1654. (nLinkWikiId && get_wiki_idx_from_id(nLinkWikiId) >= 0))
  1655. {
  1656. if (nArticleWikiId && !nLinkWikiId)
  1657. articleLink[article_link_count].article_id |= nArticleWikiId << 24;
  1658. if (article_start_y_pos)
  1659. {
  1660. start_x = articleLink[article_link_count].start_xy & 0xFF;
  1661. start_y = (articleLink[article_link_count].start_xy >> 8) & 0xFFFFFF;
  1662. end_x = articleLink[article_link_count].end_xy & 0xFF;
  1663. end_y = (articleLink[article_link_count].end_xy >> 8) & 0xFFFFFF;
  1664. articleLink[article_link_count].start_xy = (unsigned long)(start_x | ((start_y + article_start_y_pos) << 8));
  1665. articleLink[article_link_count].end_xy = (unsigned long)(end_x | ((end_y + article_start_y_pos) << 8));
  1666. }
  1667. article_link_count++;
  1668. }
  1669. offset+=sizeof(ARTICLE_LINK);
  1670. }
  1671. article_buf_pointer = file_buffer+article_header.offset_article;
  1672. display_first_page = 0; // use this to disable scrolling until the first page of the linked article is loaded
  1673. //get_article_title_from_idx(idx_article, title);
  1674. extract_title_from_article(NULL, title);
  1675. history_add(idx_article, title, bKeepPos);
  1676. saved_prev_idx_article = 0;
  1677. }
  1678. int isArticleLinkSelectedSequentialSearch(int x,int y, int start_i, int end_i)
  1679. {
  1680. int i;
  1681. int x_diff, y_diff;
  1682. int last_x_diff = 999;
  1683. int last_y_diff = 999;
  1684. int rc = -1;
  1685. int article_link_start_y_pos;
  1686. int article_link_start_x_pos;
  1687. int article_link_end_y_pos;
  1688. int article_link_end_x_pos;
  1689. int left_margin;
  1690. if (display_mode == DISPLAY_MODE_ARTICLE)
  1691. left_margin = LCD_LEFT_MARGIN;
  1692. else
  1693. left_margin = 0;
  1694. i = start_i;
  1695. while (i <= end_i)
  1696. {
  1697. article_link_start_x_pos = (articleLink[i].start_xy & 0x000000ff) + left_margin;
  1698. article_link_start_y_pos = (articleLink[i].start_xy >> 8);
  1699. article_link_end_x_pos = (articleLink[i].end_xy & 0x000000ff) + left_margin;
  1700. article_link_end_y_pos = (articleLink[i].end_xy >> 8);
  1701. if (y < article_link_start_y_pos)
  1702. y_diff = article_link_start_y_pos - y;
  1703. else if (y > article_link_end_y_pos)
  1704. y_diff = y - article_link_end_y_pos;
  1705. else
  1706. y_diff = 0;
  1707. if (x < article_link_start_x_pos)
  1708. x_diff = article_link_start_x_pos - x;
  1709. else if (x > article_link_end_x_pos)
  1710. x_diff = x - article_link_end_x_pos;
  1711. else
  1712. x_diff = 0;
  1713. if (x_diff <= LINK_X_DIFF_ALLOWANCE && y_diff <= LINK_Y_DIFF_ALLOWANCE)
  1714. {
  1715. if (((last_x_diff && !x_diff) || (last_y_diff && !y_diff)) ||
  1716. (x_diff < last_x_diff && y_diff < last_y_diff))
  1717. {
  1718. rc = i;
  1719. last_x_diff = x_diff;
  1720. last_y_diff = y_diff;
  1721. }
  1722. }
  1723. i++;
  1724. }
  1725. return rc;
  1726. }
  1727. int isArticleLinkSelected(int x,int y)
  1728. {
  1729. int i, start_i, end_i;
  1730. int bFound;
  1731. int article_link_start_y_pos;
  1732. int article_link_start_x_pos;
  1733. int article_link_end_y_pos;
  1734. int article_link_end_x_pos;
  1735. //char msg[1024];
  1736. int left_margin;
  1737. int origin_y;
  1738. if (!display_first_page || request_display_next_page)
  1739. return -1;
  1740. if (display_mode == DISPLAY_MODE_ARTICLE)
  1741. left_margin = LCD_LEFT_MARGIN;
  1742. else
  1743. left_margin = 0;
  1744. origin_y = y;
  1745. y += lcd_draw_cur_y_pos;
  1746. if (link_currently_activated >= 0 && link_currently_activated < article_link_count)
  1747. {
  1748. article_link_start_x_pos = (articleLink[link_currently_activated].start_xy & 0x000000ff) + left_margin - LINK_X_DIFF_ALLOWANCE;
  1749. article_link_start_y_pos = (articleLink[link_currently_activated].start_xy >> 8) - INITIAL_ARTICLE_SCROLL_THRESHOLD;
  1750. article_link_end_x_pos = (articleLink[link_currently_activated].end_xy & 0x000000ff) + left_margin + LINK_X_DIFF_ALLOWANCE;
  1751. article_link_end_y_pos = (articleLink[link_currently_activated].end_xy >> 8) + INITIAL_ARTICLE_SCROLL_THRESHOLD;
  1752. if (y>=article_link_start_y_pos && y<=article_link_end_y_pos && x>=article_link_start_x_pos && x<=article_link_end_x_pos)
  1753. return link_currently_activated; // if more than on links are matched, the last matched one got the higher priority
  1754. }
  1755. if (display_mode == DISPLAY_MODE_ARTICLE && x < PREVIOUS_ARTICLE_LINKABLE_SIZE &&
  1756. LCD_HEIGHT_LINES - PREVIOUS_ARTICLE_LINKABLE_SIZE <= origin_y && origin_y < LCD_HEIGHT_LINES &&
  1757. history_get_previous_idx(saved_idx_article, 0))
  1758. {
  1759. return 0; // PREVIOUS_ARTICLE_LINK
  1760. }
  1761. if (display_mode == DISPLAY_MODE_ARTICLE && (language_link_count || restricted_article) && lcd_draw_cur_y_pos == article_start_y_pos &&
  1762. LCD_BUF_WIDTH_PIXELS - LANGUAGE_LINK_WIDTH - LCD_LEFT_MARGIN <= x && x <= LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN &&
  1763. article_start_y_pos + LCD_TOP_MARGIN <= y && y <= article_start_y_pos + LCD_TOP_MARGIN + LANGUAGE_LINK_HEIGHT)
  1764. {
  1765. return 1; // SHOW_LANGUAGE_LINK
  1766. }
  1767. if (display_mode == DISPLAY_MODE_ARTICLE && (language_link_count || restricted_article) && lcd_draw_cur_y_pos == 0 &&
  1768. LCD_BUF_WIDTH_PIXELS - LANGUAGE_LINK_WIDTH - LCD_LEFT_MARGIN <= x && x <= LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN &&
  1769. LCD_TOP_MARGIN <= y && y <= LCD_TOP_MARGIN + LANGUAGE_LINK_HEIGHT)
  1770. {
  1771. return 2; // HIDE_LANGUAGE_LINK
  1772. }
  1773. start_i = 0;
  1774. end_i = article_link_count - 1;
  1775. i = article_link_count / 2;
  1776. bFound = 0;
  1777. while (start_i <= end_i && !articleLink[start_i].start_xy && !articleLink[start_i].end_xy)
  1778. start_i++; // skip the special links - PREVIOUS_ARTICLE_LINK, SHOW_LANGUAGE_LINK, HIDE_LANGUAGE_LINK
  1779. while (!bFound && start_i <= end_i)
  1780. {
  1781. if (y < (int)(articleLink[i].start_xy >> 8) - LINK_Y_DIFF_ALLOWANCE)
  1782. {
  1783. end_i = i - 1;
  1784. i = (start_i + end_i) / 2;
  1785. continue;
  1786. }
  1787. if (y > (int)(articleLink[i].end_xy >> 8) + LINK_Y_DIFF_ALLOWANCE)
  1788. {
  1789. start_i = i + 1;
  1790. i = (start_i + end_i) / 2;
  1791. continue;
  1792. }
  1793. // y range identified
  1794. return isArticleLinkSelectedSequentialSearch(x, y, start_i, end_i);
  1795. }
  1796. return -1;
  1797. }
  1798. #ifndef INCLUDED_FROM_KERNEL
  1799. int load_init_article(long idx_init_article)
  1800. {
  1801. int fd;
  1802. char file[128];
  1803. long len;
  1804. int i;
  1805. int offset,start_x,start_y,end_x,end_y;
  1806. ARTICLE_HEADER article_header;
  1807. if (idx_init_article > 0)
  1808. {
  1809. sprintf(file, "./dat/%ld/%ld/%ld/%ld", (idx_init_article / 1000000), (idx_init_article / 10000) % 100, (idx_init_article / 100) % 100, idx_init_article);
  1810. fd = wl_open(file, WL_O_RDONLY);
  1811. if (fd >= 0)
  1812. {
  1813. len = wl_read(fd, (void *)file_buffer, FILE_BUFFER_SIZE - 1);
  1814. file_buffer[len] = '\0';
  1815. wl_close(fd);
  1816. }
  1817. memcpy(&article_header,file_buffer,sizeof(ARTICLE_HEADER));
  1818. offset = sizeof(ARTICLE_HEADER);
  1819. if(article_header.article_link_count>MAX_ARTICLE_LINKS)
  1820. article_header.article_link_count = MAX_ARTICLE_LINKS;
  1821. for(i = 0; i< article_header.article_link_count;i++)
  1822. {
  1823. memcpy(&articleLink[i],file_buffer+offset,sizeof(ARTICLE_LINK));
  1824. offset+=sizeof(ARTICLE_LINK);
  1825. start_y = articleLink[i].start_xy >>8;
  1826. start_x = articleLink[i].start_xy & 0x000000ff;
  1827. end_y = articleLink[i].end_xy >>8;
  1828. end_x = articleLink[i].end_xy & 0x000000ff;
  1829. }
  1830. article_link_count = article_header.article_link_count;
  1831. article_buf_pointer = file_buffer+article_header.offset_article;
  1832. init_render_article(0);
  1833. return 0;
  1834. }
  1835. return -1;
  1836. }
  1837. #endif
  1838. #endif
  1839. #ifndef WIKIPCF
  1840. void display_link_article(long idx_article)
  1841. {
  1842. request_y_pos = article_start_y_pos;
  1843. if (idx_article == RESTRICTED_MARK_LINK)
  1844. {
  1845. bShowLanguageLinks = 0;
  1846. display_article_with_pcf(article_start_y_pos);
  1847. display_first_page = 1;
  1848. filter_option();
  1849. return;
  1850. }
  1851. else if (idx_article == PREVIOUS_ARTICLE_LINK)
  1852. {
  1853. idx_article = history_get_previous_idx(saved_idx_article, 1);
  1854. if (!idx_article)
  1855. return;
  1856. last_display_mode = DISPLAY_MODE_HISTORY;
  1857. saved_prev_idx_article = 0;
  1858. }
  1859. else if (idx_article == SHOW_LANGUAGE_LINK)
  1860. {
  1861. bShowLanguageLinks = 1;
  1862. display_article_with_pcf(-article_start_y_pos);
  1863. display_first_page = 1;
  1864. return;
  1865. }
  1866. else if (idx_article == HIDE_LANGUAGE_LINK)
  1867. {
  1868. bShowLanguageLinks = 0;
  1869. display_article_with_pcf(article_start_y_pos);
  1870. display_first_page = 1;
  1871. return;
  1872. }
  1873. else if (last_display_mode == DISPLAY_MODE_HISTORY)
  1874. history_set_y_pos(idx_article);
  1875. saved_idx_article = idx_article;
  1876. file_buffer[0] = '\0';
  1877. if (retrieve_article(idx_article))
  1878. {
  1879. return; // article not exist
  1880. }
  1881. if (restricted_article && check_restriction(idx_article))
  1882. return;
  1883. display_retrieved_article(idx_article);
  1884. }
  1885. void display_str(unsigned char *str)
  1886. {
  1887. int start_x,end_x,start_y,end_y;
  1888. int offset_x,offset_y;
  1889. int str_width;
  1890. unsigned char *p;
  1891. p = str;
  1892. // framebuffer_size ==0 iwhen WIKPCF is defined
  1893. // This causes fatal linker errors of recent gcc (Ubuntu 9.04)
  1894. int framebuffersize = framebuffer_size();
  1895. memset(framebuffer_copy,0,framebuffersize);
  1896. start_x = 0;
  1897. end_x = framebuffer_width();
  1898. start_y = framebuffer_height()/2-9;
  1899. end_y = framebuffer_height()/2+9;
  1900. // drawline_in_framebuffer_copy(framebuffer_copy,start_x,start_y,end_x,end_y);
  1901. str_width = get_external_str_pixel_width(p, DEFAULT_FONT_IDX);
  1902. offset_x = (end_x - str_width) / 2 - start_x;
  1903. offset_y = 0;
  1904. buf_draw_UTF8_str_in_copy_buffer((char *)framebuffer_copy,&str,start_x,end_x,start_y,end_y,offset_x,DEFAULT_FONT_IDX);
  1905. repaint_framebuffer(framebuffer_copy,0, 0);
  1906. }
  1907. #endif
  1908. int div_wiki(int a,int b)
  1909. {
  1910. int c =0,m = 0;
  1911. if(a<b)
  1912. return 0;
  1913. for(;;)
  1914. {
  1915. c += b;
  1916. if(c >= a)
  1917. return m;
  1918. m++;
  1919. }
  1920. }
  1921. void drawline_in_framebuffer_copy(unsigned char *buffer,int start_x,int start_y,int end_x,int end_y)
  1922. {
  1923. int i,m;
  1924. for(i = start_y;i<end_y;i++)
  1925. for(m = start_x;m<end_x;m++)
  1926. lcd_clear_pixel(buffer,m,i);
  1927. for(i = start_x ; i < end_x ; i++)
  1928. lcd_set_pixel(buffer,i, start_y);
  1929. for(i = start_y ; i < end_y ; i++)
  1930. lcd_set_pixel(buffer,start_x,i);
  1931. for(i = start_x ; i < end_x ; i++)
  1932. lcd_set_pixel(buffer,i,end_y);
  1933. for(i = start_y ; i < end_y ; i++)
  1934. lcd_set_pixel(buffer,end_x,i);
  1935. }
  1936. #ifndef WIKIPCF
  1937. // when set_article_link_number is called, the link will be "activated" in a pre-defined period
  1938. // the activated link will be inverted
  1939. void set_article_link_number(int num, unsigned long event_time)
  1940. {
  1941. if (link_currently_activated < 0)
  1942. {
  1943. link_to_be_activated = num;
  1944. link_to_be_activated_start_time = event_time;
  1945. }
  1946. else if (link_currently_activated != num || link_to_be_activated != num) // if on another link, deactivate both links since figer moves
  1947. {
  1948. reset_article_link_number();
  1949. }
  1950. }
  1951. void reset_article_link_number(void)
  1952. {
  1953. if (link_currently_inverted >= 0)
  1954. {
  1955. if (b_show_scroll_bar)
  1956. show_scroll_bar(-1);
  1957. invert_link(link_currently_inverted);
  1958. if (b_show_scroll_bar)
  1959. show_scroll_bar(-1);
  1960. }
  1961. link_currently_activated = -1;
  1962. link_to_be_activated = -1;
  1963. link_to_be_inverted = -1;
  1964. link_currently_inverted = -1;
  1965. }
  1966. void init_invert_link(void)
  1967. {
  1968. link_to_be_activated = -1;
  1969. link_currently_activated = -1;
  1970. link_to_be_inverted = -1;
  1971. link_currently_inverted = -1;
  1972. }
  1973. int get_activated_article_link_number()
  1974. {
  1975. return link_currently_activated;
  1976. }
  1977. void repaint_invert_link()
  1978. {
  1979. if (link_currently_inverted >= 0)
  1980. {
  1981. invert_link(link_currently_inverted);
  1982. }
  1983. }
  1984. void invert_link_area(int article_link_number)
  1985. {
  1986. int start_x,start_y,end_x,end_y;
  1987. int left_margin;
  1988. if (display_mode == DISPLAY_MODE_ARTICLE)
  1989. left_margin = LCD_LEFT_MARGIN;
  1990. else
  1991. left_margin = 0;
  1992. start_y = (articleLink[article_link_number].start_xy >>8) - lcd_draw_cur_y_pos;
  1993. start_x = (articleLink[article_link_number].start_xy & 0x000000ff) + left_margin - 1;
  1994. if (start_x < 0)
  1995. start_x = 0;
  1996. end_y = (articleLink[article_link_number].end_xy >>8) - lcd_draw_cur_y_pos;
  1997. end_x = (articleLink[article_link_number].end_xy & 0x000000ff) + left_margin;
  1998. if (end_x >= LCD_BUF_WIDTH_PIXELS)
  1999. end_x = LCD_BUF_WIDTH_PIXELS - 1;
  2000. if (start_y >= 0 || end_y < LCD_HEIGHT_LINES)
  2001. {
  2002. // guilib_invert_area will only invert (x, y) within LCD range
  2003. guilib_invert_area(start_x, start_y, end_x, end_y);
  2004. guilib_invert_area(start_x, start_y, start_x, start_y);
  2005. guilib_invert_area(start_x, end_y, start_x, end_y);
  2006. guilib_invert_area(end_x, start_y, end_x, start_y);
  2007. guilib_invert_area(end_x, end_y, end_x, end_y);
  2008. guilib_fb_unlock();
  2009. }
  2010. }
  2011. int is_lcd_buf_area_blank(int start_x, int start_y, int end_x, int end_y)
  2012. {
  2013. int x, y;
  2014. if (end_x < 0 || start_x >= LCD_BUF_WIDTH_PIXELS - 1)
  2015. return 1;
  2016. x = start_x;
  2017. while (x <= end_x)
  2018. {
  2019. if (x % 8 || end_x - x < 8)
  2020. {
  2021. for (y = start_y; y <= end_y; y++)
  2022. {
  2023. if (lcd_draw_buf_get_pixel(x, y))
  2024. return 0;
  2025. }
  2026. x++;
  2027. }
  2028. else
  2029. {
  2030. for (y = start_y; y <= end_y; y++)
  2031. {
  2032. if (lcd_draw_buf_get_byte(x, y))
  2033. return 0;
  2034. }
  2035. x += 8;
  2036. }
  2037. }
  2038. return 1;
  2039. }
  2040. int nothing_before_link(int article_link_number)
  2041. {
  2042. int start_x,start_y,end_x,end_y;
  2043. start_y = (articleLink[article_link_number].start_xy >> 8) + article_start_y_pos;
  2044. start_x = (articleLink[article_link_number].start_xy & 0x000000ff) + LCD_LEFT_MARGIN - 1;
  2045. if (start_x < 0)
  2046. start_x = 0;
  2047. end_y = (articleLink[article_link_number].end_xy >>8) + article_start_y_pos;
  2048. end_x = (articleLink[article_link_number].end_xy & 0x000000ff) + LCD_LEFT_MARGIN;
  2049. if (is_lcd_buf_area_blank(0, start_y, start_x - 2, end_y))
  2050. return ARTICLE_LINK_NOTHING_BEFORE;
  2051. else
  2052. return ARTICLE_LINK_SOMETHING_BEFORE;
  2053. }
  2054. int nothing_after_link(int article_link_number)
  2055. {
  2056. int start_x,start_y,end_x,end_y;
  2057. start_y = (articleLink[article_link_number].start_xy >> 8) + article_start_y_pos;
  2058. start_x = (articleLink[article_link_number].start_xy & 0x000000ff) + LCD_LEFT_MARGIN - 1;
  2059. if (start_x < 0)
  2060. start_x = 0;
  2061. end_y = (articleLink[article_link_number].end_xy >>8) + article_start_y_pos;
  2062. end_x = (articleLink[article_link_number].end_xy & 0x000000ff) + LCD_LEFT_MARGIN;
  2063. if (is_lcd_buf_area_blank(end_x + 2, start_y, LCD_BUF_WIDTH_PIXELS - 1, end_y))
  2064. return ARTICLE_LINK_NOTHING_AFTER;
  2065. else
  2066. return ARTICLE_LINK_SOMETHING_AFTER;
  2067. }
  2068. void invert_link(int article_link_number)
  2069. {
  2070. long article_id;
  2071. int local_link_number;
  2072. int bNothingBeforeLink;
  2073. int bNothingAfterLink;
  2074. if(article_link_number<0)
  2075. return;
  2076. article_id = articleLink[article_link_number].article_id;
  2077. invert_link_area(article_link_number);
  2078. if (display_mode == DISPLAY_MODE_ARTICLE && article_id != EXTERNAL_ARTICLE_LINK)
  2079. {
  2080. if (!articleLinkBeforeAfter[article_link_number])
  2081. articleLinkBeforeAfter[article_link_number] = nothing_before_link(article_link_number) | nothing_after_link(article_link_number);
  2082. bNothingBeforeLink = articleLinkBeforeAfter[article_link_number] & ARTICLE_LINK_NOTHING_BEFORE;
  2083. local_link_number = article_link_number - 1;
  2084. while (bNothingBeforeLink && local_link_number >= 0 && article_id == articleLink[local_link_number].article_id)
  2085. {
  2086. if (!articleLinkBeforeAfter[local_link_number])
  2087. articleLinkBeforeAfter[local_link_number] = nothing_before_link(local_link_number) | nothing_after_link(local_link_number);
  2088. bNothingAfterLink = articleLinkBeforeAfter[local_link_number] & ARTICLE_LINK_NOTHING_AFTER;
  2089. if (bNothingAfterLink)
  2090. {
  2091. invert_link_area(local_link_number);
  2092. bNothingBeforeLink = articleLinkBeforeAfter[local_link_number] & ARTICLE_LINK_NOTHING_BEFORE;
  2093. local_link_number--;
  2094. }
  2095. else
  2096. bNothingBeforeLink = 0;
  2097. }
  2098. bNothingAfterLink = articleLinkBeforeAfter[article_link_number] & ARTICLE_LINK_NOTHING_AFTER;
  2099. local_link_number = article_link_number + 1;
  2100. while (bNothingAfterLink && local_link_number < article_link_count && article_id == articleLink[local_link_number].article_id)
  2101. {
  2102. if (!articleLinkBeforeAfter[local_link_number])
  2103. articleLinkBeforeAfter[local_link_number] = nothing_before_link(local_link_number) | nothing_after_link(local_link_number);
  2104. bNothingBeforeLink = articleLinkBeforeAfter[local_link_number] & ARTICLE_LINK_NOTHING_BEFORE;
  2105. if (bNothingBeforeLink)
  2106. {
  2107. invert_link_area(local_link_number);
  2108. bNothingAfterLink = articleLinkBeforeAfter[local_link_number] & ARTICLE_LINK_NOTHING_AFTER;
  2109. local_link_number++;
  2110. }
  2111. else
  2112. bNothingAfterLink = 0;
  2113. }
  2114. }
  2115. }
  2116. // invert link when timeout
  2117. int check_invert_link()
  2118. {
  2119. if (link_to_be_activated >= 0 && time_diff(get_time_ticks(), link_to_be_activated_start_time) >=
  2120. seconds_to_ticks(LINK_ACTIVATION_TIME_THRESHOLD))
  2121. {
  2122. link_currently_activated = link_to_be_activated;
  2123. link_to_be_inverted = link_to_be_activated;
  2124. link_to_be_inverted_start_time = link_to_be_activated_start_time;
  2125. link_to_be_activated = -1;
  2126. if (link_currently_inverted >= 0)
  2127. {
  2128. invert_link(link_currently_inverted);
  2129. link_currently_inverted = -1;
  2130. }
  2131. }
  2132. if (link_to_be_inverted >= 0 &&
  2133. ((display_mode == DISPLAY_MODE_ARTICLE &&
  2134. time_diff(get_time_ticks(), link_to_be_inverted_start_time) >= seconds_to_ticks(LINK_INVERT_ACTIVATION_TIME_THRESHOLD)) ||
  2135. time_diff(get_time_ticks(), link_to_be_inverted_start_time) >= seconds_to_ticks(LIST_LINK_INVERT_ACTIVATION_TIME_THRESHOLD)))
  2136. {
  2137. if (link_currently_inverted >= 0)
  2138. invert_link(link_currently_inverted);
  2139. invert_link(link_to_be_inverted);
  2140. link_currently_inverted = link_to_be_inverted;
  2141. link_to_be_inverted = -1;
  2142. }
  2143. if (link_to_be_activated >= 0 || link_to_be_inverted >= 0)
  2144. return 1;
  2145. else
  2146. return 0;
  2147. }
  2148. void open_article_link(int x,int y)
  2149. {
  2150. int article_link_number;
  2151. long idx_article;
  2152. article_link_number = isArticleLinkSelected(x,y);
  2153. if(article_link_number >= 0)
  2154. {
  2155. idx_article = articleLink[article_link_number].article_id;
  2156. if (idx_article == EXTERNAL_ARTICLE_LINK)
  2157. {
  2158. idx_article = wiki_lang_link_search(externalLink[article_link_number].link_str);
  2159. if (!idx_article)
  2160. return;
  2161. }
  2162. display_link_article(idx_article);
  2163. }
  2164. }
  2165. void open_article_link_with_link_number(int article_link_number)
  2166. {
  2167. long idx;
  2168. if (article_link_number < 0 || articleLink[article_link_number].article_id <= 0)
  2169. return;
  2170. display_first_page = 0; // use this to disable scrolling until the first page of the linked article is loaded
  2171. idx = articleLink[article_link_number].article_id;
  2172. if (idx == RESTRICTED_MARK_LINK)
  2173. {
  2174. #ifdef INCLUDED_FROM_KERNEL
  2175. delay_us(100000);
  2176. #endif
  2177. invert_link(article_link_number);
  2178. }
  2179. else if (idx == EXTERNAL_ARTICLE_LINK)
  2180. {
  2181. idx = wiki_lang_link_search(externalLink[article_link_number].link_str);
  2182. if (!idx)
  2183. return;
  2184. }
  2185. display_link_article(idx);
  2186. }
  2187. #endif
  2188. void msg_info(char *data)
  2189. {
  2190. #ifdef WIKIPCF
  2191. printf(data);
  2192. #else
  2193. msg(MSG_INFO,data);
  2194. #endif
  2195. }
  2196. int framebuffer_size()
  2197. {
  2198. #ifdef WIKIPCF
  2199. return 0;
  2200. #else
  2201. return guilib_framebuffer_size();
  2202. #endif
  2203. }
  2204. int framebuffer_width()
  2205. {
  2206. #ifdef WIKIPCF
  2207. return 0;
  2208. #else
  2209. return guilib_framebuffer_width();
  2210. #endif
  2211. }
  2212. int framebuffer_height()
  2213. {
  2214. #ifdef WIKIPCF
  2215. return 0;
  2216. #else
  2217. return guilib_framebuffer_height();
  2218. #endif
  2219. }
  2220. int strchr_idx(char *s, char c)
  2221. {
  2222. int rc = -1;
  2223. int i = 0;
  2224. while (rc < 0 && s[i])
  2225. {
  2226. if (s[i] == c)
  2227. rc = i;
  2228. i++;
  2229. }
  2230. return rc;
  2231. }
  2232. #ifndef WIKIPCF
  2233. int draw_bmf_char(ucs4_t u,int font,int x,int y, int inverted, int b_clear)
  2234. {
  2235. bmf_bm_t *bitmap;
  2236. charmetric_bmf Cmetrics;
  2237. //pcf_SCcharmet_t sm;
  2238. int bytes_to_process;
  2239. int x_base;
  2240. int x_offset;
  2241. int y_offset;
  2242. int x_bit_idx;
  2243. int i; // bitmap byte index
  2244. int j; // bitmap bit index
  2245. pcffont_bmf_t *pPcfFont;
  2246. pPcfFont = &pcfFonts[font];
  2247. pres_bmfbm(u, pPcfFont, &bitmap, &Cmetrics);
  2248. if (bitmap == NULL)
  2249. {
  2250. return -1;
  2251. }
  2252. if (b_clear)
  2253. {
  2254. for (i = 0; i < pPcfFont->Fmetrics.linespace; i++)
  2255. {
  2256. for (j = 0; j < Cmetrics.widthDevice; j++)
  2257. {
  2258. if (inverted)
  2259. lcd_set_framebuffer_pixel(x + j, y + i);
  2260. else
  2261. lcd_clear_framebuffer_pixel(x + j, y + i);
  2262. }
  2263. }
  2264. }
  2265. if(u==32)
  2266. {
  2267. x += Cmetrics.widthDevice;
  2268. return x;
  2269. }
  2270. bytes_to_process = Cmetrics.widthBytes * Cmetrics.height;
  2271. x_base = x + Cmetrics.LSBearing;
  2272. x_offset = 0;
  2273. y_offset = pPcfFont->Fmetrics.linespace - (pPcfFont->Fmetrics.descent + Cmetrics.ascent);
  2274. x_bit_idx = x_base & 0x07;
  2275. if (x + Cmetrics.widthDevice >= LCD_BUF_WIDTH_PIXELS)
  2276. return -1;
  2277. for (i = 0; i < bytes_to_process; i++)
  2278. {
  2279. j = 7;
  2280. while (j >= 0)
  2281. {
  2282. if (x_offset >= Cmetrics.widthBits)
  2283. {
  2284. x_offset = 0;
  2285. y_offset++;
  2286. }
  2287. if (x_offset < Cmetrics.width)
  2288. {
  2289. if (bitmap[i] & (1 << j))
  2290. {
  2291. if (inverted)
  2292. lcd_clear_framebuffer_pixel(x_base + x_offset, y+y_offset);
  2293. else
  2294. lcd_set_framebuffer_pixel(x_base + x_offset, y+y_offset);
  2295. }
  2296. //else if (b_clear)
  2297. //{
  2298. // if (inverted)
  2299. // lcd_set_framebuffer_pixel(x_base + x_offset, y+y_offset);
  2300. // else
  2301. // lcd_clear_framebuffer_pixel(x_base + x_offset, y+y_offset);
  2302. //}
  2303. }
  2304. x_offset++;
  2305. x_bit_idx++;
  2306. if (!(x_bit_idx & 0x07))
  2307. {
  2308. x_bit_idx = 0;
  2309. }
  2310. j--;
  2311. }
  2312. }
  2313. x += Cmetrics.widthDevice;
  2314. return x;
  2315. }
  2316. int buf_draw_bmf_char(char *buf, ucs4_t u,int font,int x,int y, int inverted)
  2317. {
  2318. bmf_bm_t *bitmap;
  2319. charmetric_bmf Cmetrics;
  2320. //pcf_SCcharmet_t sm;
  2321. int bytes_to_process;
  2322. int x_base;
  2323. int x_offset;
  2324. int y_offset;
  2325. int x_bit_idx;
  2326. int i; // bitmap byte index
  2327. int j; // bitmap bit index
  2328. pcffont_bmf_t *pPcfFont;
  2329. pPcfFont = &pcfFonts[font];
  2330. pres_bmfbm(u, pPcfFont, &bitmap, &Cmetrics);
  2331. if (bitmap == NULL)
  2332. {
  2333. return -1;
  2334. }
  2335. if(u==32)
  2336. {
  2337. x += Cmetrics.widthDevice;
  2338. return x;
  2339. }
  2340. bytes_to_process = Cmetrics.widthBytes * Cmetrics.height;
  2341. x_base = x + Cmetrics.LSBearing;
  2342. x_offset = 0;
  2343. y_offset = pPcfFont->Fmetrics.linespace - (pPcfFont->Fmetrics.descent + Cmetrics.ascent);
  2344. x_bit_idx = x_base & 0x07;
  2345. if (x + Cmetrics.widthDevice >= LCD_BUF_WIDTH_PIXELS)
  2346. return -1;
  2347. for (i = 0; i < bytes_to_process; i++)
  2348. {
  2349. j = 7;
  2350. while (j >= 0)
  2351. {
  2352. if (x_offset >= Cmetrics.widthBits)
  2353. {
  2354. x_offset = 0;
  2355. y_offset++;
  2356. }
  2357. if (x_offset < Cmetrics.width)
  2358. {
  2359. if (bitmap[i] & (1 << j))
  2360. {
  2361. if (inverted)
  2362. {
  2363. unsigned int byte = ((x_base+x_offset) + LCD_VRAM_WIDTH_PIXELS * (y+y_offset)) / 8;
  2364. unsigned int bit = ((x_base+x_offset) + LCD_VRAM_WIDTH_PIXELS * (y+y_offset)) % 8;
  2365. buf[byte] ^= (1 << (7 - bit));
  2366. }
  2367. else
  2368. {
  2369. unsigned int byte = ((x_base+x_offset) + LCD_VRAM_WIDTH_PIXELS * (y+y_offset)) / 8;
  2370. unsigned int bit = ((x_base+x_offset) + LCD_VRAM_WIDTH_PIXELS * (y+y_offset)) % 8;
  2371. buf[byte] |= (1 << (7 - bit));
  2372. }
  2373. }
  2374. }
  2375. x_offset++;
  2376. x_bit_idx++;
  2377. if (!(x_bit_idx & 0x07))
  2378. {
  2379. x_bit_idx = 0;
  2380. }
  2381. j--;
  2382. }
  2383. }
  2384. x += Cmetrics.widthDevice;
  2385. return x;
  2386. }
  2387. #endif
  2388. int GetFontLinespace(int font)
  2389. {
  2390. return pcfFonts[font - 1].Fmetrics.linespace;
  2391. }
  2392. void msg_on_lcd(int x, int y, char *fmt, ...)
  2393. {
  2394. #ifdef INCLUDED_FROM_KERNEL
  2395. va_list args;
  2396. char msg[100];
  2397. va_start(args, fmt);
  2398. vsprintf (msg, fmt, args);
  2399. guilib_clear_area(x, y, 239, y+18);
  2400. render_string(DEFAULT_FONT_IDX, x, y, msg, strlen(msg), 0);
  2401. va_end(args);
  2402. #endif
  2403. }
  2404. void msg_on_lcd_clear(int x, int y)
  2405. {
  2406. #ifdef INCLUDED_FROM_KERNEL
  2407. // guilib_fb_lock();
  2408. guilib_clear_area(x, y, 239, y+18);
  2409. // guilib_fb_unlock();
  2410. #endif
  2411. }
  2412. void extract_title_from_article(unsigned char *article_buf, unsigned char *title)
  2413. {
  2414. unsigned char c, c2;
  2415. int bDone = 0;
  2416. ARTICLE_HEADER article_header;
  2417. int lenTitle = 0;
  2418. if (!article_buf)
  2419. article_buf = file_buffer;
  2420. memcpy(&article_header, article_buf, sizeof(ARTICLE_HEADER));
  2421. article_buf += article_header.offset_article;
  2422. while (!bDone)
  2423. {
  2424. c = *article_buf;
  2425. if (c <= MAX_ESC_CHAR)
  2426. {
  2427. article_buf++;
  2428. switch(c)
  2429. {
  2430. case ESC_0_SPACE_LINE:
  2431. article_buf++;
  2432. break;
  2433. case ESC_2_NEW_LINE_SAME_FONT:
  2434. title[lenTitle++] = ' '; // append a blank for wrapped title
  2435. break;
  2436. case ESC_3_NEW_LINE_WITH_FONT:
  2437. c2 = *article_buf++;
  2438. if ((c2 & 0x07) != TITLE_FONT_IDX)
  2439. bDone = 1;
  2440. break;
  2441. default:
  2442. bDone = 1;
  2443. break;
  2444. }
  2445. }
  2446. else
  2447. {
  2448. title[lenTitle++] = *article_buf++;
  2449. if (lenTitle >= MAX_TITLE_ACTUAL - 1)
  2450. bDone = 1;
  2451. }
  2452. }
  2453. title[lenTitle] = '\0';
  2454. }
  2455. void draw_progress_bar(int progressCount)
  2456. {
  2457. int x;
  2458. if (!progressCount)
  2459. {
  2460. memset(framebuffer, 0, LCD_BUF_WIDTH_BYTES * 4);
  2461. }
  2462. else
  2463. {
  2464. if (progressCount > LCD_BUF_WIDTH_PIXELS)
  2465. progressCount = LCD_BUF_WIDTH_PIXELS;
  2466. x = 0;
  2467. while (x < progressCount)
  2468. {
  2469. if (x % 8 || progressCount - x < 8)
  2470. {
  2471. lcd_set_framebuffer_pixel(x, 1);
  2472. lcd_set_framebuffer_pixel(x, 2);
  2473. x++;
  2474. }
  2475. else
  2476. {
  2477. lcd_set_framebuffer_byte(0xFF, x, 1);
  2478. lcd_set_framebuffer_byte(0xFF, x, 2);
  2479. x += 8;
  2480. }
  2481. }
  2482. while (x < LCD_BUF_WIDTH_PIXELS)
  2483. {
  2484. if (x % 8 || LCD_BUF_WIDTH_PIXELS - x < 8)
  2485. {
  2486. lcd_clear_framebuffer_pixel(x, 1);
  2487. lcd_clear_framebuffer_pixel(x, 2);
  2488. x++;
  2489. }
  2490. else
  2491. {
  2492. lcd_set_framebuffer_byte(0, x, 1);
  2493. lcd_set_framebuffer_byte(0, x, 2);
  2494. x += 8;
  2495. }
  2496. }
  2497. }
  2498. }