Ejemplo n.º 1
0
const char* get_encoding(font_family* family) {
  static const char* latin = "iso8859-1";
  static const char* hankaku = "jisx0201.1976-0";
  static const char* kanji = "jisx0208.1983-0";
  static const char* testchar = "\xEF\xBD\xB1\xE4\xBA\x9C";
  static bool check[2];
  static BFont font;
  font.SetFamilyAndFace(*family, B_REGULAR_FACE);
  font.GetHasGlyphs(testchar, 2, check);
  if(check[1])
    return kanji;
  if(check[0])
    return hankaku;
  return latin;
}
Ejemplo n.º 2
0
void
FontSelectionView::UpdateFontsMenu()
{
	int32 numFamilies = count_font_families();

	fFontsMenu->RemoveItems(0, fFontsMenu->CountItems(), true);

	BFont font = fCurrentFont;

	font_family currentFamily;
	font_style currentStyle;
	font.GetFamilyAndStyle(&currentFamily, &currentStyle);

	for (int32 i = 0; i < numFamilies; i++) {
		font_family family;
		uint32 flags;
		if (get_font_family(i, &family, &flags) != B_OK)
			continue;

		// if we're setting the fixed font, we only want to show fixed fonts
		if (!strcmp(Name(), "fixed") && (flags & B_IS_FIXED) == 0)
			continue;

		font.SetFamilyAndFace(family, B_REGULAR_FACE);

		BMessage* message = new BMessage(kMsgSetFamily);
		message->AddString("family", family);
		message->AddString("name", Name());

		BMenuItem* familyItem;
		if (fStylesMenuField != NULL) {
			familyItem = new BMenuItem(family, message);
		} else {
			// Each family item has a submenu with all styles for that font.
			BMenu* stylesMenu = new BMenu(family);
			_AddStylesToMenu(font, stylesMenu);
			familyItem = new BMenuItem(stylesMenu, message);
		}

		familyItem->SetMarked(strcmp(family, currentFamily) == 0);
		fFontsMenu->AddItem(familyItem);
		familyItem->SetTarget(this);
	}

	// Separate styles menu for only the current font.
	if (fStylesMenuField != NULL)
		_AddStylesToMenu(fCurrentFont, fStylesMenuField->Menu());
}