xref: /haiku/src/tests/kits/interface/bfont/GetBoundingBoxesTest.cpp (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 #include <Application.h>
2 #include <Font.h>
3 #include <Rect.h>
4 #include <stdio.h>
5 
6 void
7 GetBoundingBoxesAsGlyphsTest(BFont *font)
8 {
9 	const char string[] = "test string";
10 	int32 numChars = 11;
11 	BRect rectArray[numChars];
12 	font->GetBoundingBoxesAsGlyphs(string, numChars, B_SCREEN_METRIC, rectArray);
13 
14 	for (int32 i=0; i<numChars; i++) {
15 		rectArray[i].PrintToStream();
16 	}
17 }
18 
19 void
20 GetBoundingBoxesAsStringTest(BFont *font)
21 {
22 	const char string[] = "test string";
23 	int32 numChars = 11;
24 	BRect rectArray[numChars];
25 	escapement_delta delta = { 0.0, 0.0 };
26 	font->GetBoundingBoxesAsString(string, numChars, B_SCREEN_METRIC, &delta, rectArray);
27 
28 	for (int32 i=0; i<numChars; i++) {
29 		rectArray[i].PrintToStream();
30 	}
31 }
32 
33 void
34 GetBoundingBoxesForStringsTest(BFont *font)
35 {
36 	char string[] = "test string";
37 	int32 numStrings = 1;
38 	const char* stringArray[numStrings];
39 	stringArray[0] = string;
40 	BRect rectArray[numStrings];
41 	escapement_delta delta = { 0.0, 0.0 };
42 	font->GetBoundingBoxesForStrings(stringArray, numStrings, B_SCREEN_METRIC, &delta, rectArray);
43 
44 	for (int32 i=0; i<numStrings; i++) {
45 		rectArray[i].PrintToStream();
46 	}
47 }
48 
49 int main()
50 {
51 	BApplication app("application/x-vnd-Test.GetBoundingBoxesTest");
52 	BFont font(be_plain_font);
53 	//font.SetRotation(45);
54 	//font.SetShear(45);
55 	font.SetSpacing(B_CHAR_SPACING);
56 	printf("\nGetBoundingBoxesAsGlyphsTest\n");
57 	GetBoundingBoxesAsGlyphsTest(&font);
58 	printf("\nGetBoundingBoxesAsStringTest\n");
59 	GetBoundingBoxesAsStringTest(&font);
60 	printf("\nGetBoundingBoxesForStringsTest\n");
61 	GetBoundingBoxesForStringsTest(&font);
62 }
63