1/* 2** Copyright 2008, Stefano Ceccherini (stefano.ceccherini@gmail.com). 3** All rights reserved. 4** Distributed under the terms of the MIT License. 5*/ 6 7#include <Application.h> 8#include <Font.h> 9 10#include <stdio.h> 11#include <stdlib.h> 12 13#include <WidthBuffer.h> 14 15 16class App : public BApplication { 17public: 18 App(); 19 ~App(); 20 virtual void ReadyToRun(); 21 22private: 23 _BWidthBuffer_ *fWidthBuffer; 24 thread_id fThread; 25 26 int32 TesterFunc(); 27 static int32 _thread(void *data); 28 29}; 30 31 32int main() 33{ 34 App app; 35 app.Run(); 36 return 0; 37} 38 39 40App::App() 41 :BApplication("application/x-vnd-WidthBufferTest") 42{ 43 fWidthBuffer = new _BWidthBuffer_; 44 fThread = spawn_thread(App::_thread, "widthbuffer tester", 45 B_NORMAL_PRIORITY, this); 46} 47 48 49void 50App::ReadyToRun() 51{ 52 resume_thread(fThread); 53} 54 55 56App::~App() 57{ 58 status_t status; 59 wait_for_thread(fThread, &status); 60 delete fWidthBuffer; 61} 62 63 64int32 65App::TesterFunc() 66{ 67 FILE *file = fopen("/boot/beos/etc/termcap", "r"); 68 if (file != NULL) { 69 char buffer[512]; 70 while (fgets(buffer, 512, file)) { 71 float width = fWidthBuffer->StringWidth(buffer, 0, 72 strlen(buffer), be_plain_font); 73 printf("string: %s, width: %f\n", buffer, width); 74 } 75 fclose(file); 76 } 77 78 PostMessage(B_QUIT_REQUESTED); 79 80 return 0; 81} 82 83 84int32 85App::_thread(void *data) 86{ 87 return static_cast<App *>(data)->TesterFunc(); 88} 89 90