status_t CanvasMessage::ReadFontState(BFont& font) { uint8 encoding, spacing; uint16 face; uint32 flags, familyAndStyle; font_direction direction; float falseBoldWidth, rotation, shear, size; Read(direction); Read(encoding); Read(flags); Read(spacing); Read(shear); Read(rotation); Read(falseBoldWidth); Read(size); Read(face); status_t result = Read(familyAndStyle); if (result != B_OK) return result; font.SetFamilyAndStyle(familyAndStyle); font.SetEncoding(encoding); font.SetFlags(flags); font.SetSpacing(spacing); font.SetShear(shear); font.SetRotation(rotation); font.SetFalseBoldWidth(falseBoldWidth); font.SetSize(size); font.SetFace(face); return B_OK; }
void PDFWriter::DrawString(char *string, float escapementNoSpace, float escapementSpace) { REPORT(kDebug, fPage, "DrawString string=\"%s\", escapementNoSpace=%f, " "escapementSpace=%f, at %f, %f", string, escapementNoSpace, escapementSpace, fState->penX, fState->penY); if (IsDrawing()) { // text color is always the high color and not the pattern! SetColor(fState->foregroundColor); } // convert string to UTF8 BString utf8; if (fState->beFont.Encoding() == B_UNICODE_UTF8) { utf8 = string; } else { ToUtf8(fState->beFont.Encoding()-1, string, utf8); } // convert string in UTF8 to unicode UCS2 BString unicode; ToUnicode(utf8.String(), unicode); // need font object to calculate width of utf8 code point BFont font = fState->beFont; font.SetEncoding(B_UNICODE_UTF8); // constants to calculate position of next character const double rotation = DEGREE2RAD(fState->beFont.Rotation()); const bool rotate = rotation != 0.0; const double cos1 = rotate ? cos(rotation) : 1; const double sin1 = rotate ? -sin(rotation) : 0; BPoint start(fState->penX, fState->penY); BeginTransparency(); // If !MakesPDF() all the effort below just for the bounding box! // draw each character const char *c = utf8.String(); const unsigned char *u = (unsigned char*)unicode.String(); for (int i = 0; i < unicode.Length(); i += 2) { int s = CodePointSize((char*)c); float w = font.StringWidth(c, s); if (MakesPDF() && IsClipping()) { ClipChar(&font, (char*)u, c, s, w); } else { DrawChar(u[0]*256+u[1], c, s); } // position of next character if (*(unsigned char*)c <= 0x20) { // should test if c is a white-space! w += escapementSpace; } else { w += escapementNoSpace; } fState->penX += w * cos1; fState->penY += w * sin1; // next character c += s; u += 2; } EndTransparency(); // text line processing (for non rotated text only!) BPoint end(fState->penX, fState->penY); BRect bounds; font_height height; font.GetHeight(&height); bounds.left = start.x; bounds.right = end.x; bounds.top = start.y - height.ascent; bounds.bottom = end.y + height.descent; TextSegment* segment = new TextSegment(utf8.String(), start, escapementSpace, escapementNoSpace, &bounds, &font, pdfSystem()); fTextLine.Add(segment); }
void ChatWindow::MessageReceived( BMessage* aMessage ) { switch( aMessage->what ) { case SHOW_MESSAGE: { const char *msg; aMessage->FindString( "msg", &msg ); time_t _now = time( NULL ); struct tm *now = localtime( &_now ); BString *str = NULL; BString *str2 = NULL; char *string = NULL; Person *person = NULL; for( int i = 0; i < iWindow->GetProfile()->GetUserlist()->GetList()->CountItems(); i++ ) { person = ( Person* ) iWindow->GetProfile()->GetUserlist()->GetList()->ItemAt( i ); if( iWho == person->GetUIN() ) { str = new BString(); str->SetTo( person->GetDisplay() ); break; } } if( !str ) { str = new BString(); *str << ( int32 ) iWho; } BFont *font = new BFont( be_plain_font ); font->SetSize( 16.0 ); font->SetEncoding( B_ISO_8859_2 ); rgb_color yellow = { 255, 255, 0, 0 }; rgb_color red = { 255, 0, 0, 0 }; rgb_color white = { 255, 255, 255, 0 }; string = ( char* ) calloc( strlen( "[00:00] " ), 1 ); sprintf( string, "[%02d:%02d] ", now->tm_hour, now->tm_min); str2 = new BString(); str2->SetTo( string ); free( string ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2->Length(), font, B_FONT_ALL, &yellow ); iChat->Insert( iChat->TextLength(), str2->String(), str2->Length() ); str->Append( ": " ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str->Length(), font, B_FONT_ALL, &red ); iChat->Insert( iChat->TextLength(), str->String(), str->Length() ); str2->SetTo( msg ); str2->Append( "\n" ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2->Length(), font, B_FONT_ALL, &white ); iChat->Insert( iChat->TextLength(), str2->String(), str2->Length() ); BScrollBar * scrollBar = iScrollView->ScrollBar( B_VERTICAL ); if( scrollBar->LockLooper() ) { float max,min; scrollBar->GetRange( &min, &max ); scrollBar->SetValue( max ); scrollBar->UnlockLooper(); } delete str; delete str2; break; } case BEGG_SEND: { if( iSayControl->LockLooper()) { if( !(*iSayControl->Text() ) ) { /* nothing to send */ iSayControl->UnlockLooper(); break; } /* first we add message into chat window */ time_t _now = time( NULL ); struct tm * now = localtime( &_now ); BString str; BString str2; char *string; // int id = iNetwork->GetIdent(); BFont *font = new BFont( be_plain_font ); font->SetSize( 16.0 ); font->SetEncoding( B_ISO_8859_2 ); rgb_color yellow = { 255, 255, 0, 0 }; rgb_color green = { 0, 255, 0, 0 }; rgb_color white = { 255, 255, 255, 0 }; string = ( char* ) calloc( strlen( "[00:00] " ), 1 ); sprintf( string, "[%02d:%02d] ", now->tm_hour, now->tm_min ); str2.SetTo( string ); free( string ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2.Length(), font, B_FONT_ALL, &yellow ); iChat->Insert( iChat->TextLength(), str2.String(), str2.Length() ); str.SetTo( iWindow->GetProfile()->GetProfileName() ); str.Append( ": " ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str.Length(), font, B_FONT_ALL, &green ); iChat->Insert( iChat->TextLength(), str.String(), str.Length() ); str2.SetTo( iSayControl->Text() ); str2.Append( "\n" ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2.Length(), font, B_FONT_ALL, &white ); iChat->Insert( iChat->TextLength(), str2.String(), str2.Length() ); /* scroll down */ BScrollBar * scrollBar = iScrollView->ScrollBar( B_VERTICAL ); if( scrollBar->LockLooper() ) { float max,min; scrollBar->GetRange( &min, &max ); scrollBar->SetValue( max ); scrollBar->UnlockLooper(); } /* sending... */ BMessage *newmessage; newmessage = new BMessage( SEND_MESSAGE ); newmessage->AddInt32( "who", iWho ); newmessage->AddString( "msg", iSayControl->Text()); BMessenger( iNetwork ).SendMessage( newmessage ); delete newmessage; /* clearing edit box */ iSayControl->SetText( NULL ); iSayControl->UnlockLooper(); } break; } default: BWindow::MessageReceived( aMessage ); break; } }
ChatWindow::ChatWindow( Network *aNetwork, MainWindow *aWindow, uin_t aWho ) : BWindow( CHATWIN_RECT, CHATWIN_NAME, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE ) { iNetwork = aNetwork; iWindow = aWindow; iWho = aWho; SetSizeLimits( 300, 2000, 200, 2000 ); /* we're fixing a title and checking that we have that number in our people list if true, set to iDisplay */ Person *person; BString title = Title(); BString *pe = NULL; for( int i = 0; i < iWindow->GetProfile()->GetUserlist()->GetList()->CountItems(); i++ ) { person = ( Person* ) iWindow->GetProfile()->GetUserlist()->GetList()->ItemAt( i ); if( aWho == person->GetUIN() ) { pe = new BString( person->GetDisplay() ); break; } } if( !pe ) { pe = new BString(); pe->SetTo( _T("[Stranger]") ); } title.Append( pe->String() ); title << " (" << iWho << ")"; SetTitle( title.String()); /* making a default background */ BRect r = Bounds(); BView *someView; someView = new BView( r, "some view", B_FOLLOW_ALL, B_WILL_DRAW ); someView->SetViewColor( 60, 60, 60 ); AddChild( someView ); /* 'chat' at base of BTextView */ r = someView->Bounds(); r.InsetBy( 10, 10 ); r.right -= B_V_SCROLL_BAR_WIDTH; r.bottom -= 25; BRect textRect = BRect( 5, 5, r.Width() - 5, r.Height() - 5 ); iChat = new BTextView( r, "chat view", textRect, B_FOLLOW_ALL, B_WILL_DRAW ); iChat->MakeEditable( false ); iChat->SetStylable( true ); BFont *font = new BFont( be_plain_font ); font->SetSize( 15.0 ); font->SetEncoding( B_ISO_8859_2 ); iChat->SetFontAndColor( font ); iScrollView = new BScrollView( "scroll view", iChat, B_FOLLOW_ALL, 0, false, true ); someView->AddChild( iScrollView ); iChat->SetViewColor( 70, 70, 70 ); /* new message edit box */ r = someView->Bounds(); r.InsetBy( 10, 10 ); r.top = r.bottom - 15; iSayControl = new BTextControl( r, "say control", "", NULL, new BMessage( BEGG_SEND ), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM ); iSayControl->MakeFocus( true ); float width, height; iSayControl->GetPreferredSize( &width, &height ); iSayControl->SetDivider( width / 2 ); iSayControl->SetFont( font ); someView->AddChild( iSayControl ); }