INT_PTR CALLBACK OptDlgProc(HWND hDlg,UINT msg,WPARAM wparam,LPARAM lparam) { RECT rect; plgsettings *ps; //0: current; 1: original logmsg("OptDlgProc"); switch(msg){ case WM_INITDIALOG: logmsg("OptDlgProc::INITDIALOG"); TranslateDialogDefault(hDlg); ps=(plgsettings*)malloc(sizeof(plgsettings)*2); loadDBSettings(&ps[0]); ps[1]=ps[0]; SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)ps); SetWindowLongPtr(hwnd, GWL_STYLE, WS_POPUP | WS_SIZEBOX); SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED); SetWindowLongPtr(GetDlgItem(hDlg,IDC_TREE1),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hDlg,IDC_TREE1),GWL_STYLE)|TVS_NOHSCROLL|TVS_CHECKBOXES); SetWindowLongPtr(GetDlgItem(hDlg,IDC_TREE2),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hDlg,IDC_TREE1),GWL_STYLE)|TVS_NOHSCROLL|TVS_CHECKBOXES); CheckDlgButton(hDlg, IDC_RADIO1+ps->align-1, BST_CHECKED); CheckDlgButton(hDlg, IDC_RADIO10+9-ps->salign, BST_CHECKED); CheckDlgButton(hDlg, IDC_CHECK1, ps->altShadow); CheckDlgButton(hDlg, IDC_CHECK2, ps->showMsgWindow); CheckDlgButton(hDlg, IDC_CHECK3, ps->transparent); CheckDlgButton(hDlg, IDC_CHECK4, ps->showShadow); CheckDlgButton(hDlg, IDC_CHECK5, ps->messages); SetDlgItemText(hDlg, IDC_EDIT2, ps->msgformat); CheckDlgButton(hDlg, IDC_CHECK6, ps->a_user); CheckDlgButton(hDlg, IDC_CHECK7, ps->showmystatus); SetDlgItemInt(hDlg, IDC_EDIT1, ps->distance, 0); SendDlgItemMessage(hDlg, IDC_SLIDER1, TBM_SETRANGE, 0, MAKELONG(0, 255)); SendDlgItemMessage(hDlg, IDC_SLIDER1, TBM_SETPOS, TRUE, (LPARAM)ps->alpha); { TCHAR buf[20]; mir_sntprintf(buf, SIZEOF(buf), _T("%d %%"), ps->alpha*100/255); SetDlgItemText(hDlg, IDC_ALPHATXT, buf); } SetDlgItemInt(hDlg, IDC_EDIT5, ps->timeout, 0); FillCheckBoxTree(GetDlgItem(hDlg, IDC_TREE1), ps->announce); FillCheckBoxTree(GetDlgItem(hDlg, IDC_TREE2), ps->showWhen); return 0; case WM_HSCROLL: if (LOWORD(wparam)==SB_ENDSCROLL||LOWORD(wparam)==SB_THUMBPOSITION||LOWORD(wparam)==SB_ENDSCROLL) return 0; ps=(plgsettings*)GetWindowLongPtr(hDlg, GWLP_USERDATA); ps->alpha=SendDlgItemMessage(hDlg, IDC_SLIDER1, TBM_GETPOS, 0, 0); { TCHAR buf[20]; mir_sntprintf(buf, SIZEOF(buf), _T("%d %%"), ps->alpha*100/255); SetDlgItemText(hDlg, IDC_ALPHATXT, buf); } goto xxx; case WM_DESTROY: logmsg("OptDlgProc::DESTROY"); ps=(plgsettings*)GetWindowLongPtr(hDlg, GWLP_USERDATA); ps[0]=ps[1]; saveDBSettings(&ps[0]); SetWindowLongPtr(hwnd, GWL_STYLE, WS_POPUP); SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED); SetWindowPos(hwnd, 0, ps->winxpos, ps->winypos, ps->winx, ps->winy, SWP_NOZORDER|SWP_NOACTIVATE); SetLayeredWindowAttributes(hwnd, ps->bkclr, ps->alpha, (ps->transparent?LWA_COLORKEY:0)|LWA_ALPHA); free((void*)GetWindowLongPtr(hDlg, GWLP_USERDATA)); return 0; case WM_COMMAND: logmsg("OptDlgProc::COMMAND"); ps=(plgsettings*)GetWindowLongPtr(hDlg, GWLP_USERDATA); switch (LOWORD(wparam)) { case IDC_BUTTON7: MessageBox(hDlg, TranslateT("Variables:\n %n : Nick\n %m : Message\n %l : New line"), TranslateT("Help"), MB_ICONINFORMATION|MB_OK); return 0; case IDC_BUTTON5: SendMessage(hwnd, WM_USER+1, (WPARAM)TranslateT("Miranda NG is great and this is a long message."), 0); break; case IDC_BUTTON1: selectFont(hDlg, &(ps->lf)); break; case IDC_BUTTON2: selectColor(hDlg, &ps->clr_status); break; case IDC_BUTTON6: selectColor(hDlg, &ps->clr_msg); break; case IDC_BUTTON3: selectColor(hDlg, &ps->clr_shadow); break; case IDC_BUTTON4: selectColor(hDlg, &ps->bkclr); break; case IDC_CHECK4: ps->showShadow=IsDlgButtonChecked(hDlg, IDC_CHECK4); break; case IDC_CHECK1: ps->altShadow=IsDlgButtonChecked(hDlg, IDC_CHECK1); break; case IDC_CHECK2: ps->showMsgWindow=IsDlgButtonChecked(hDlg, IDC_CHECK2); case IDC_EDIT1: ps->distance=GetDlgItemInt(hDlg, IDC_EDIT1, 0, 0); break; case IDC_EDIT5: ps->timeout=GetDlgItemInt(hDlg, IDC_EDIT5, 0, 0); break; case IDC_CHECK3: ps->transparent=IsDlgButtonChecked(hDlg, IDC_CHECK3); break; case IDC_CHECK5: ps->messages=IsDlgButtonChecked(hDlg, IDC_CHECK5); break; case IDC_CHECK6: ps->a_user=IsDlgButtonChecked(hDlg, IDC_CHECK6); break; case IDC_CHECK7: ps->showmystatus=IsDlgButtonChecked(hDlg, IDC_CHECK7); break; case IDC_RADIO1: case IDC_RADIO2: case IDC_RADIO3: case IDC_RADIO4: case IDC_RADIO5: case IDC_RADIO6: case IDC_RADIO7: case IDC_RADIO8: case IDC_RADIO9: if (IsDlgButtonChecked(hDlg, LOWORD(wparam))) ps->align=LOWORD(wparam)-IDC_RADIO1+1; break; case IDC_RADIO10: case IDC_RADIO11: case IDC_RADIO12: case IDC_RADIO13: case IDC_RADIO14: case IDC_RADIO15: case IDC_RADIO16: case IDC_RADIO17: case IDC_RADIO18: if (IsDlgButtonChecked(hDlg, LOWORD(wparam))) ps->salign=10-(LOWORD(wparam)-IDC_RADIO10+1); break; } xxx: saveDBSettings(ps); SetWindowPos(hwnd, 0, 0, 0, ps->winx, ps->winy, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); SetLayeredWindowAttributes(hwnd, db_get_dw(NULL,THIS_MODULE, "bkclr", DEFAULT_BKCLR), db_get_b(NULL,THIS_MODULE, "alpha", DEFAULT_ALPHA), (db_get_b(NULL,THIS_MODULE, "transparent", DEFAULT_TRANPARENT)?LWA_COLORKEY:0)|LWA_ALPHA); InvalidateRect(hwnd, 0, TRUE); SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); return 0; case WM_NOTIFY: logmsg("OptDlgProc::NOTIFY"); switch(((LPNMHDR)lparam)->code){ case TVN_SETDISPINFO: case NM_CLICK: case NM_RETURN: case TVN_SELCHANGED: if (((LPNMHDR)lparam)->idFrom==IDC_TREE1) SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); break; case PSN_APPLY: ps=(plgsettings*)GetWindowLongPtr(hDlg, GWLP_USERDATA); GetWindowRect(hwnd, &rect); ps->winx=rect.right-rect.left; ps->winy=rect.bottom-rect.top; ps->winxpos=rect.left; ps->winypos=rect.top; ps->announce=MakeCheckBoxTreeFlags(GetDlgItem(hDlg, IDC_TREE1)); ps->showWhen=MakeCheckBoxTreeFlags(GetDlgItem(hDlg, IDC_TREE2)); GetDlgItemText(hDlg, IDC_EDIT2, ps->msgformat, 255); ps[1]=ps[0]; //apply current settings at closing saveDBSettings(ps); SetLayeredWindowAttributes(hwnd, db_get_dw(NULL,THIS_MODULE, "bkclr", DEFAULT_BKCLR), db_get_b(NULL,THIS_MODULE, "alpha", DEFAULT_ALPHA), (db_get_b(NULL,THIS_MODULE, "transparent", DEFAULT_TRANPARENT)?LWA_COLORKEY:0)|LWA_ALPHA); InvalidateRect(hwnd, 0, TRUE); break; } break; } return 0; }
QtFontButton::QtFontButton(QWidget *parent) : QToolButton(parent) { setText(font()); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); connect(this, SIGNAL(clicked()), SLOT(selectFont())); }
void Window::createWindow(int w, int h, bool r) { screen_w = w; screen_h = h; //lineHeight = w / 15; if (r) { w *= 2; h *= 2; } glfwInit(); win = glfwCreateWindow(w, h, "Island-Survival", NULL, NULL); glfwSetWindowSizeCallback(win, [](GLFWwindow*, int w, int h) { screen_h = h; screen_w = w; //lineHeight = w / 15; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, w, h, 0.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }); glfwMakeContextCurrent(win); glewInit(); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, w , h , 0.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); selectFont(30, ANSI_CHARSET, "微软雅黑"); }
/* * device_Text should have the side-effect that the * given text is drawn at the given location. * The text should be rotated according to rot (degrees) * * R_GE_gcontext parameters that should be honoured (if possible): * font, cex, ps, col, gamma */ static void SWF_Text( double x, double y, const char *str, double rot, double hadj, const pGEcontext plotParams, pDevDesc deviceInfo) { /* Shortcut pointers to variables of interest. */ swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific; if( swfInfo->debug == TRUE ){ fprintf(swfInfo->logFile, "SWF_Text: Writing Text \"%s\"\n", str); fflush(swfInfo->logFile); } /* It is possible that this will be very expensive and storing * a single text object in swfInfo may be better. */ SWFText text_object = newSWFText(); SWFDisplayItem text_display; /*Ming (0,0) is the top left, convert to R (0,0) at bottom left*/ y = deviceInfo->top - y; //found = !strcmp(name, fontlist->family->fxname); // Tell the text object to use the font previously loaded SWFText_setFont(text_object, selectFont(plotParams->fontface, plotParams->fontfamily, swfInfo)); // Set the height of the text SWFText_setHeight(text_object, plotParams->ps * plotParams->cex); // Set the color of the text byte red = R_RED(plotParams->col); byte green = R_GREEN(plotParams->col); byte blue = R_BLUE(plotParams->col); byte alpha = R_ALPHA(plotParams->col); SWFText_setColor(text_object, red, green, blue, alpha); // Add a string to the text object SWFText_addString(text_object, str, NULL); // Add the text object to the movie (at 0,0) text_display = SWFMovie_add(swfInfo->m, (SWFBlock) text_object); addToDisplayList( text_display ); // Move to correct coordinate and rotate SWFDisplayItem_moveTo(text_display, x, y); SWFDisplayItem_rotate(text_display, rot); }
void ConsoleMaster::createNewWindow() { ConsoleWindow* win = new ConsoleWindow(&db_); windows_.append(win); QSettings settings; window_font_ = settings.value(SettingsKeys::FONT, QFont("Ubuntu Mono", 9)).value<QFont>(); win->setFont(window_font_); QObject::connect(win, SIGNAL(createNewWindow()), this, SLOT(createNewWindow())); QObject::connect(&ros_thread_, SIGNAL(connected(bool)), win, SLOT(connected(bool))); QObject::connect(this, SIGNAL(fontChanged(const QFont &)), win, SLOT(setFont(const QFont &))); QObject::connect(win, SIGNAL(selectFont()), this, SLOT(selectFont())); QObject::connect(win, SIGNAL(readBagFile()), &bag_reader_, SLOT(promptForBagFile())); if (!ros_thread_.isRunning()) { // There's only one ROS thread, and it services every window. We need to initialize // it and its connections to the LogDatabase when we first create a window, but // after that it doesn't need to be modified again. QObject::connect(&ros_thread_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )), &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) )); QObject::connect(&ros_thread_, SIGNAL(spun()), &db_, SLOT(processQueue())); ros_thread_.start(); }
DialogSettingsEditor::DialogSettingsEditor(QWidget* parent) : QWidget(parent) { m_ui.setupUi(this); const QFont& font(SETTINGS.getEditorFont()); m_ui.m_fontName->setText(font.family()); m_ui.m_fontSize->setValue(font.pointSize()); m_ui.m_tabWidth->setValue(SETTINGS.getTabStopWidth()); m_ui.m_useSpaces->setChecked(SETTINGS.getUseSpaces()); m_ui.m_verticalLinePos->setValue(SETTINGS.getVertLinePos()); m_ui.m_wrapLines->setChecked(SETTINGS.getWrapLines()); m_ui.m_removeTrailingSpaces->setChecked(SETTINGS.getRemoveTrailingSpaces()); connect(m_ui.m_selectFontButton, SIGNAL(clicked()), this, SLOT(selectFont())); }
void SpreadSheet::createActions() { cell_sumAction = new QAction(tr("Sum"), this); connect(cell_sumAction, SIGNAL(triggered()), this, SLOT(actionSum())); cell_addAction = new QAction(tr("&Add"), this); cell_addAction->setShortcut(Qt::CTRL | Qt::Key_Plus); connect(cell_addAction, SIGNAL(triggered()), this, SLOT(actionAdd())); cell_subAction = new QAction(tr("&Subtract"), this); cell_subAction->setShortcut(Qt::CTRL | Qt::Key_Minus); connect(cell_subAction, SIGNAL(triggered()), this, SLOT(actionSubtract())); cell_mulAction = new QAction(tr("&Multiply"), this); cell_mulAction->setShortcut(Qt::CTRL | Qt::Key_multiply); connect(cell_mulAction, SIGNAL(triggered()), this, SLOT(actionMultiply())); cell_divAction = new QAction(tr("&Divide"), this); cell_divAction->setShortcut(Qt::CTRL | Qt::Key_division); connect(cell_divAction, SIGNAL(triggered()), this, SLOT(actionDivide())); fontAction = new QAction(tr("Font..."), this); fontAction->setShortcut(Qt::CTRL | Qt::Key_F); connect(fontAction, SIGNAL(triggered()), this, SLOT(selectFont())); colorAction = new QAction(QPixmap(16, 16), tr("Background &Color..."), this); connect(colorAction, SIGNAL(triggered()), this, SLOT(selectColor())); clearAction = new QAction(tr("Clear"), this); clearAction->setShortcut(Qt::Key_Delete); connect(clearAction, SIGNAL(triggered()), this, SLOT(clear())); aboutSpreadSheet = new QAction(tr("About Spreadsheet"), this); connect(aboutSpreadSheet, SIGNAL(triggered()), this, SLOT(showAbout())); exitAction = new QAction(tr("E&xit"), this); connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); printAction = new QAction(tr("&Print"), this); connect(printAction, SIGNAL(triggered()), this, SLOT(print())); firstSeparator = new QAction(this); firstSeparator->setSeparator(true); secondSeparator = new QAction(this); secondSeparator->setSeparator(true); }
FTFont *text3d :: makeFont(const char*fontfile){ if(m_aafont)delete m_aafont;m_aafont=NULL; if(m_pyfont)delete m_pyfont;m_pyfont=NULL; m_font=NULL; // TextureFont looks nicer, but does not allow for texturing m_aafont = new FTGLTextureFont(fontfile); if(m_aafont && m_aafont->Error()) { delete m_aafont; m_aafont = NULL; } m_pyfont = new FTGLPolygonFont(fontfile); if (m_pyfont && m_pyfont->Error()){ delete m_pyfont; m_pyfont = NULL; } return selectFont(); }
ItemSettings::ItemSettings(ItemProperties *prop,QWidget *parent):QWidget(parent,Qt::Tool) { setupUi(this); this->prop = prop; this->fontColor = prop->fontColor; this->penColor = prop->itemPen.color(); this->brushColor = prop->itemBrush.color(); QPixmap penColor(45,11); penColor.fill(prop->itemPen.color()); QIcon penIcon(penColor); this->pb_penColor->setIcon(penIcon); this->pb_penColor->setIconSize(QSize(45,11)); this->sd_penWidth->setValue(prop->itemPen.width()); this->cb_penStyle->setCurrentIndex(this->prop->itemPen.style() - 1); QPixmap brushColor(45,11); brushColor.fill(prop->itemBrush.color()); QIcon brushIcon(brushColor); this->pb_brushColor->setIcon(brushIcon); this->pb_brushColor->setIconSize(QSize(45,11)); this->cb_brushStyle->setCurrentIndex(this->prop->itemBrush.style()); QPixmap fontColor(45,11); fontColor.fill(prop->fontColor); QIcon fontIcon(fontColor); this->pb_fontColor->setIcon(fontIcon); this->pb_fontColor->setIconSize(QSize(45,11)); connect(pb_penColor,SIGNAL(released()),this,SLOT(setPenColor())); connect(pb_brushColor,SIGNAL(released()),this,SLOT(setBrushColor())); connect(pb_done,SIGNAL(released()),this,SLOT(saveSettings())); connect(pb_selectFont,SIGNAL(released()),this,SLOT(selectFont())); connect(pb_fontColor,SIGNAL(released()),this,SLOT(setFontColor())); int p_midX = parent->x() + 100; int p_midY = parent->y() + 150; this->move(p_midX , p_midY) ; this->activateWindow(); }
//static LLView* LLFlyoutButton::fromXML(LLXMLNodePtr node, LLView* parent, LLUICtrlFactory* factory) { std::string label(""); node->getAttributeString("label", label); LLRect rect; createRect(node, rect, parent, LLRect()); LLFlyoutButton* flyout_button = new LLFlyoutButton("flyout_button", rect, label); std::string list_position; node->getAttributeString("list_position", list_position); if (list_position == "below") { flyout_button->mListPosition = BELOW; } else if (list_position == "above") { flyout_button->mListPosition = ABOVE; } if (LLFontGL* font = selectFont(node)) flyout_button->mActionButton->setFont(font); flyout_button->initFromXML(node, parent); for (LLXMLNodePtr child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { if (child->hasName(LL_FLYOUT_BUTTON_ITEM_TAG)) { std::string label(child->getTextContents()); child->getAttributeString("label", label); std::string value(label); child->getAttributeString("value", value); flyout_button->add(label, LLSD(value)); } } flyout_button->updateLayout(); return flyout_button; }
GLuint drawChar_To_Texture(const char* s) { wchar_t w; HDC hDC = wglGetCurrentDC(); // 选择字体字号、颜色 // 不指定字体名字,操作系统提供默认字体 // 设置颜色为白色 selectFont(FONT_SIZE, DEFAULT_CHARSET, ""); glColor3f(1.0f, 1.0f, 1.0f); // 转化为宽字符 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, s, 2, &w, 1); // 计算绘制的位置 int width, x, y; GetCharWidth32W(hDC, w, w, &width); // 取得字符的宽度 x = (TEXTURE_SIZE - width) / 2; y = FONT_SIZE / 8; //glWindowPos2iARB(x, y); // 一个扩展函数 GLuint list = glGenLists(1); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_FOG); glDisable(GL_TEXTURE_2D); wglUseFontBitmaps(hDC, w, 1, list); glCallList(list); glDeleteLists(list, 1); GLuint texID; glGenTextures(1, &texID); glBindTexture(GL_TEXTURE_2D, texID); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE4, 0, 0, TEXTURE_SIZE, TEXTURE_SIZE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); return texID; }
void CFontDisplay::display(int fontsize,char *str,GLfloat *fontlocation,GLfloat *fontcolor) { if (fontcolor==NULL) { fontcolor=m_fontcolor; } if (fontlocation==NULL) { fontlocation=m_fontlocation; } //glClear(GL_COLOR_BUFFER_BIT); selectFont(fontsize, DEFAULT_CHARSET, "Times New Roman"); //默认设定 glColor3fv(fontcolor); glRasterPos2fv(fontlocation); // DrawString("Hello, World!"); // glRasterPos2f(0.5,0.8); drawCNString(str); // drawChar_To_Texture(("我")); // drawChar_To_Texture("ff"); // glutSwapBuffers(); }
void RichTextEdit::showBar() { if (m_bar) return; m_bar = new QToolBar(this); btnBG = new ColorToolButton(m_bar, m_edit->background()); set_button(btnBG, "bgcolor", I18N_NOOP("Bac&kground color")); connect(btnBG, SIGNAL(colorChanged(QColor)), this, SLOT(bgColorChanged(QColor))); btnFG = new ColorToolButton(m_bar, m_edit->foreground()); set_button(btnFG, "fgcolor", I18N_NOOP("&Text color")); connect(btnFG, SIGNAL(colorChanged(QColor)), this, SLOT(fgColorChanged(QColor))); connect(btnFG, SIGNAL(aboutToShow()), this, SLOT(showFgPopup())); m_bar->addSeparator(); btnBold = new QToolButton(m_bar); set_button(btnBold, "text_bold", I18N_NOOP("&Bold")); btnBold->setToggleButton(true); connect(btnBold, SIGNAL(toggled(bool)), this, SLOT(toggleBold(bool))); btnItalic = new QToolButton(m_bar); set_button(btnItalic, "text_italic", I18N_NOOP("&Italic")); btnItalic->setToggleButton(true); connect(btnItalic, SIGNAL(toggled(bool)), this, SLOT(toggleItalic(bool))); btnUnderline = new QToolButton(m_bar); set_button(btnUnderline, "text_under", I18N_NOOP("&Underline")); btnUnderline->setToggleButton(true); connect(btnUnderline, SIGNAL(toggled(bool)), this, SLOT(toggleUnderline(bool))); m_bar->addSeparator(); QToolButton *btn = new QToolButton(m_bar); set_button(btn, "text", I18N_NOOP("Text &font")); connect(btn, SIGNAL(clicked()), this, SLOT(selectFont())); connect(m_edit, SIGNAL(currentFontChanged(const QFont&)), this, SLOT(fontChanged(const QFont&))); }
void text3d :: setFontSize(){ if (!m_font)return; int fs=static_cast<int>(m_fontSize*m_precision); if(fs<0)fs=-fs; if (m_pyfont) { if (! m_pyfont->FaceSize(fs) ) error("unable to set fontsize!"); if(m_pyfont->Error()) error("error setting fontsize"); } if (m_aafont) { if (! m_aafont->FaceSize(fs) ) error("unable to set antialiased-fontfize!"); if(m_aafont->Error()) error("error setting aa-fontsize"); } m_font=selectFont(); setModified(); }
/* * device_StrWidth should return the width of the given * string in DEVICE units. * An example is ... * * static double X11_StrWidth(const char *str, * const pGEcontext gc, * pDevDesc dd) * * R_GE_gcontext parameters that should be honoured (if possible): * font, cex, ps */ static double SWF_StrWidth( const char *str, const pGEcontext plotParams, pDevDesc deviceInfo ) { /* Shortcut pointers to variables of interest. */ swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific; if( swfInfo->debug == TRUE ){ fprintf(swfInfo->logFile, "SWF_StrWidth: "); fflush(swfInfo->logFile); } SWFText text_object = newSWFText(); // Tell the text object to use the font previously loaded SWFText_setFont(text_object, selectFont(plotParams->fontface, plotParams->fontfamily, swfInfo)); // Set the height of the text SWFText_setHeight(text_object, plotParams->ps * plotParams->cex); if( swfInfo->debug == TRUE ) fprintf(swfInfo->logFile, "Honoring ps=%7.2f, cex=%7.2f\n", plotParams->ps, plotParams->cex); float width = SWFText_getStringWidth(text_object, str); if( swfInfo->debug == TRUE ){ fprintf(swfInfo->logFile, "\tCalculated Width of \"%s\" as %7.2f\n", str, width); fflush(swfInfo->logFile); } destroySWFText(text_object); return width; }
// ============================================================= PythonSettings::PythonSettings(QWidget* parent, const char* name) : QWidget(parent), Ui_PythonSettingsData(), PreferencesEntry() { setINIFileSectionName("PYTHON"); setupUi(this); setObjectName(name); // signals and slots connections connect( choose_button, SIGNAL( clicked() ), this, SLOT( fileSelected() ) ); connect( clear_button, SIGNAL( clicked() ), this, SLOT( clearStartupScript() ) ); connect( font_button, SIGNAL( clicked() ), this, SLOT( selectFont() ) ); connect(new_button, SIGNAL(pressed()), table, SLOT(addEmptyRow())); connect(remove_button, SIGNAL(pressed()), table, SLOT(removeSelection())); registerWidgetForHelpSystem_(widget_stack->widget(0), "pythonInterpreter.html#startup_script"); registerWidgetForHelpSystem_(widget_stack->widget(1), "pythonInterpreter.html#create_hotkeys"); setWidgetStackName("Python"); setWidgetStack(widget_stack); registerWidgets_(); }
// static LLView* LLButton::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) { std::string name("button"); node->getAttributeString("name", name); std::string label = name; node->getAttributeString("label", label); std::string label_selected = label; node->getAttributeString("label_selected", label_selected); LLFontGL* font = selectFont(node); std::string image_unselected; if (node->hasAttribute("image_unselected")) node->getAttributeString("image_unselected",image_unselected); std::string image_selected; if (node->hasAttribute("image_selected")) node->getAttributeString("image_selected",image_selected); std::string image_hover_selected; if (node->hasAttribute("image_hover_selected")) node->getAttributeString("image_hover_selected",image_hover_selected); std::string image_hover_unselected; if (node->hasAttribute("image_hover_unselected")) node->getAttributeString("image_hover_unselected",image_hover_unselected); std::string image_disabled_selected; if (node->hasAttribute("image_disabled_selected")) node->getAttributeString("image_disabled_selected",image_disabled_selected); std::string image_disabled; if (node->hasAttribute("image_disabled")) node->getAttributeString("image_disabled",image_disabled); std::string image_overlay; node->getAttributeString("image_overlay", image_overlay); LLFontGL::HAlign image_overlay_alignment = LLFontGL::HCENTER; std::string image_overlay_alignment_string; if (node->hasAttribute("image_overlay_alignment")) { node->getAttributeString("image_overlay_alignment", image_overlay_alignment_string); image_overlay_alignment = LLFontGL::hAlignFromName(image_overlay_alignment_string); } LLButton *button = new LLButton(name, LLRect(), image_unselected, image_selected, LLStringUtil::null, NULL, parent, font, label, label_selected); node->getAttributeS32("pad_right", button->mRightHPad); node->getAttributeS32("pad_left", button->mLeftHPad); BOOL is_toggle = button->getIsToggle(); node->getAttributeBOOL("toggle", is_toggle); button->setIsToggle(is_toggle); if(image_hover_selected != LLStringUtil::null) button->setImageHoverSelected(image_hover_selected); if(image_hover_unselected != LLStringUtil::null) button->setImageHoverUnselected(image_hover_unselected); if(image_disabled_selected != LLStringUtil::null) button->setImageDisabledSelected(image_disabled_selected ); if(image_disabled != LLStringUtil::null) button->setImageDisabled(image_disabled); if(image_overlay != LLStringUtil::null) button->setImageOverlay(image_overlay, image_overlay_alignment); if (node->hasAttribute("halign")) { LLFontGL::HAlign halign = selectFontHAlign(node); button->setHAlign(halign); } if (node->hasAttribute("scale_image")) { BOOL needsScale = FALSE; node->getAttributeBOOL("scale_image",needsScale); button->setScaleImage( needsScale ); } if(label.empty()) { button->setLabelUnselected(node->getTextContents()); } if (label_selected.empty()) { button->setLabelSelected(node->getTextContents()); } if (node->hasAttribute("help_url")) { std::string help_url; node->getAttributeString("help_url",help_url); button->setHelpURLCallback(help_url); } button->initFromXML(node, parent); return button; }
bool gfxGDIShaper::ShapeText(gfxContext *aContext, const PRUnichar *aText, uint32_t aOffset, uint32_t aLength, int32_t aScript, gfxShapedText *aShapedText) { DCFromContext dc(aContext); AutoSelectFont selectFont(dc, static_cast<gfxGDIFont*>(mFont)->GetHFONT()); uint32_t length = aLength; nsAutoTArray<WORD,500> glyphArray; if (!glyphArray.SetLength(length)) { return false; } WORD *glyphs = glyphArray.Elements(); DWORD ret = ::GetGlyphIndicesW(dc, aText, length, glyphs, GGI_MARK_NONEXISTING_GLYPHS); if (ret == GDI_ERROR) { return false; } for (int k = 0; k < length; k++) { if (glyphs[k] == 0xFFFF) return false; } SIZE size; nsAutoTArray<int,500> partialWidthArray; if (!partialWidthArray.SetLength(length)) { return false; } BOOL success = ::GetTextExtentExPointI(dc, glyphs, length, INT_MAX, NULL, partialWidthArray.Elements(), &size); if (!success) { return false; } gfxTextRun::CompressedGlyph g; gfxTextRun::CompressedGlyph *charGlyphs = aShapedText->GetCharacterGlyphs(); uint32_t i; int32_t lastWidth = 0; int32_t appUnitsPerDevPixel = aShapedText->GetAppUnitsPerDevUnit(); for (i = 0; i < length; ++i) { uint32_t offset = aOffset + i; int32_t advancePixels = partialWidthArray[i] - lastWidth; lastWidth = partialWidthArray[i]; int32_t advanceAppUnits = advancePixels * appUnitsPerDevPixel; WCHAR glyph = glyphs[i]; NS_ASSERTION(!gfxFontGroup::IsInvalidChar(aText[i]), "Invalid character detected!"); bool atClusterStart = charGlyphs[offset].IsClusterStart(); if (advanceAppUnits >= 0 && gfxShapedWord::CompressedGlyph::IsSimpleAdvance(advanceAppUnits) && gfxShapedWord::CompressedGlyph::IsSimpleGlyphID(glyph) && atClusterStart) { charGlyphs[offset].SetSimpleGlyph(advanceAppUnits, glyph); } else { gfxShapedText::DetailedGlyph details; details.mGlyphID = glyph; details.mAdvance = advanceAppUnits; details.mXOffset = 0; details.mYOffset = 0; aShapedText->SetGlyphs(offset, g.SetComplex(atClusterStart, true, 1), &details); } } return true; }
// static LLView* LLComboBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) { std::string label(""); node->getAttributeString("label", label); LLRect rect; createRect(node, rect, parent, LLRect()); BOOL allow_text_entry = FALSE; node->getAttributeBOOL("allow_text_entry", allow_text_entry); S32 max_chars = 20; node->getAttributeS32("max_chars", max_chars); LLComboBox* combo_box = new LLComboBox("combo_box", rect, label); combo_box->setAllowTextEntry(allow_text_entry, max_chars); if (LLFontGL* font = selectFont(node)) combo_box->mButton->setFont(font); const std::string& contents = node->getValue(); if (contents.find_first_not_of(" \n\t") != contents.npos) { llerrs << "Legacy combo box item format used! Please convert to <combo_item> tags!" << llendl; } else { LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { if (child->hasName("combo_item") || child->hasName("combo_box.item")) { std::string label = child->getTextContents(); child->getAttributeString("label", label); std::string value = label; child->getAttributeString("value", value); LLScrollListItem * item=combo_box->add(label, LLSD(value) ); if(item && child->hasAttribute("tool_tip")) { std::string tool_tip = label; child->getAttributeString("tool_tip", tool_tip); item->getColumn(0)->setToolTip(tool_tip); } } } } //Do this AFTER combo_items are set up so setValue is actually able to select the correct initial entry. combo_box->initFromXML(node, parent); // if providing user text entry or descriptive label // don't select an item under the hood if (!combo_box->acceptsTextInput() && combo_box->mLabel.empty()) { combo_box->selectFirstItem(); } return combo_box; }
void TermTab::SetupFontsButton () { const auto action = Toolbar_->addAction (tr ("Select font..."), this, SLOT (selectFont ())); action->setProperty ("ActionIcon", "preferences-desktop-font"); }
void gfxGDIFont::Initialize() { NS_ASSERTION(!mMetrics, "re-creating metrics? this will leak"); LOGFONTW logFont; if (mAdjustedSize == 0.0) { mAdjustedSize = mStyle.size; if (mStyle.sizeAdjust != 0.0 && mAdjustedSize > 0.0) { // to implement font-size-adjust, we first create the "unadjusted" font FillLogFont(logFont, mAdjustedSize); mFont = ::CreateFontIndirectW(&logFont); // initialize its metrics so we can calculate size adjustment Initialize(); // calculate the properly adjusted size, and then proceed // to recreate mFont and recalculate metrics gfxFloat aspect = mMetrics->xHeight / mMetrics->emHeight; mAdjustedSize = mStyle.GetAdjustedSize(aspect); // delete the temporary font and metrics ::DeleteObject(mFont); mFont = nsnull; delete mMetrics; mMetrics = nsnull; } } FillLogFont(logFont, mAdjustedSize); mFont = ::CreateFontIndirectW(&logFont); mMetrics = new gfxFont::Metrics; ::memset(mMetrics, 0, sizeof(*mMetrics)); AutoDC dc; SetGraphicsMode(dc.GetDC(), GM_ADVANCED); AutoSelectFont selectFont(dc.GetDC(), mFont); // Get font metrics OUTLINETEXTMETRIC oMetrics; TEXTMETRIC& metrics = oMetrics.otmTextMetrics; if (0 < GetOutlineTextMetrics(dc.GetDC(), sizeof(oMetrics), &oMetrics)) { mMetrics->superscriptOffset = (double)oMetrics.otmptSuperscriptOffset.y; // Some fonts have wrong sign on their subscript offset, bug 410917. mMetrics->subscriptOffset = fabs((double)oMetrics.otmptSubscriptOffset.y); mMetrics->strikeoutSize = (double)oMetrics.otmsStrikeoutSize; mMetrics->strikeoutOffset = (double)oMetrics.otmsStrikeoutPosition; mMetrics->underlineSize = (double)oMetrics.otmsUnderscoreSize; mMetrics->underlineOffset = (double)oMetrics.otmsUnderscorePosition; const MAT2 kIdentityMatrix = { {0, 1}, {0, 0}, {0, 0}, {0, 1} }; GLYPHMETRICS gm; DWORD len = GetGlyphOutlineW(dc.GetDC(), PRUnichar('x'), GGO_METRICS, &gm, 0, nsnull, &kIdentityMatrix); if (len == GDI_ERROR || gm.gmptGlyphOrigin.y <= 0) { // 56% of ascent, best guess for true type mMetrics->xHeight = ROUND((double)metrics.tmAscent * DEFAULT_XHEIGHT_FACTOR); } else { mMetrics->xHeight = gm.gmptGlyphOrigin.y; } mMetrics->emHeight = metrics.tmHeight - metrics.tmInternalLeading; gfxFloat typEmHeight = (double)oMetrics.otmAscent - (double)oMetrics.otmDescent; mMetrics->emAscent = ROUND(mMetrics->emHeight * (double)oMetrics.otmAscent / typEmHeight); mMetrics->emDescent = mMetrics->emHeight - mMetrics->emAscent; if (oMetrics.otmEMSquare > 0) { mFUnitsConvFactor = float(GetAdjustedSize() / oMetrics.otmEMSquare); } } else { // Make a best-effort guess at extended metrics // this is based on general typographic guidelines // GetTextMetrics can fail if the font file has been removed // or corrupted recently. BOOL result = GetTextMetrics(dc.GetDC(), &metrics); if (!result) { NS_WARNING("Missing or corrupt font data, fasten your seatbelt"); mIsValid = PR_FALSE; memset(mMetrics, 0, sizeof(*mMetrics)); return; } mMetrics->xHeight = ROUND((float)metrics.tmAscent * DEFAULT_XHEIGHT_FACTOR); mMetrics->superscriptOffset = mMetrics->xHeight; mMetrics->subscriptOffset = mMetrics->xHeight; mMetrics->strikeoutSize = 1; mMetrics->strikeoutOffset = ROUND(mMetrics->xHeight * 0.5f); // 50% of xHeight mMetrics->underlineSize = 1; mMetrics->underlineOffset = -ROUND((float)metrics.tmDescent * 0.30f); // 30% of descent mMetrics->emHeight = metrics.tmHeight - metrics.tmInternalLeading; mMetrics->emAscent = metrics.tmAscent - metrics.tmInternalLeading; mMetrics->emDescent = metrics.tmDescent; } mMetrics->internalLeading = metrics.tmInternalLeading; mMetrics->externalLeading = metrics.tmExternalLeading; mMetrics->maxHeight = metrics.tmHeight; mMetrics->maxAscent = metrics.tmAscent; mMetrics->maxDescent = metrics.tmDescent; mMetrics->maxAdvance = metrics.tmMaxCharWidth; mMetrics->aveCharWidth = PR_MAX(1, metrics.tmAveCharWidth); // The font is monospace when TMPF_FIXED_PITCH is *not* set! // See http://msdn2.microsoft.com/en-us/library/ms534202(VS.85).aspx if (!(metrics.tmPitchAndFamily & TMPF_FIXED_PITCH)) { mMetrics->maxAdvance = mMetrics->aveCharWidth; } // Cache the width of a single space. SIZE size; GetTextExtentPoint32W(dc.GetDC(), L" ", 1, &size); mMetrics->spaceWidth = ROUND(size.cx); // Cache the width of digit zero. // XXX MSDN (http://msdn.microsoft.com/en-us/library/ms534223.aspx) // does not say what the failure modes for GetTextExtentPoint32 are - // is it safe to assume it will fail iff the font has no '0'? if (GetTextExtentPoint32W(dc.GetDC(), L"0", 1, &size)) { mMetrics->zeroOrAveCharWidth = ROUND(size.cx); } else { mMetrics->zeroOrAveCharWidth = mMetrics->aveCharWidth; } mSpaceGlyph = 0; if (metrics.tmPitchAndFamily & TMPF_TRUETYPE) { WORD glyph; DWORD ret = GetGlyphIndicesW(dc.GetDC(), L" ", 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS); if (ret != GDI_ERROR && glyph != 0xFFFF) { mSpaceGlyph = glyph; } } SanitizeMetrics(mMetrics, GetFontEntry()->mIsBadUnderlineFont); mFontFace = cairo_win32_font_face_create_for_logfontw_hfont(&logFont, mFont); cairo_matrix_t sizeMatrix, ctm; cairo_matrix_init_identity(&ctm); cairo_matrix_init_scale(&sizeMatrix, mAdjustedSize, mAdjustedSize); cairo_font_options_t *fontOptions = cairo_font_options_create(); if (mAntialiasOption != kAntialiasDefault) { cairo_font_options_set_antialias(fontOptions, GetCairoAntialiasOption(mAntialiasOption)); } mScaledFont = cairo_scaled_font_create(mFontFace, &sizeMatrix, &ctm, fontOptions); cairo_font_options_destroy(fontOptions); if (!mScaledFont || cairo_scaled_font_status(mScaledFont) != CAIRO_STATUS_SUCCESS) { #ifdef DEBUG char warnBuf[1024]; sprintf(warnBuf, "Failed to create scaled font: %s status: %d", NS_ConvertUTF16toUTF8(mFontEntry->Name()).get(), mScaledFont ? cairo_scaled_font_status(mScaledFont) : 0); NS_WARNING(warnBuf); #endif } mIsValid = PR_TRUE; #if 0 printf("Font: %p (%s) size: %f\n", this, NS_ConvertUTF16toUTF8(GetName()).get(), mStyle.size); printf(" emHeight: %f emAscent: %f emDescent: %f\n", mMetrics.emHeight, mMetrics.emAscent, mMetrics.emDescent); printf(" maxAscent: %f maxDescent: %f maxAdvance: %f\n", mMetrics.maxAscent, mMetrics.maxDescent, mMetrics.maxAdvance); printf(" internalLeading: %f externalLeading: %f\n", mMetrics.internalLeading, mMetrics.externalLeading); printf(" spaceWidth: %f aveCharWidth: %f xHeight: %f\n", mMetrics.spaceWidth, mMetrics.aveCharWidth, mMetrics.xHeight); printf(" uOff: %f uSize: %f stOff: %f stSize: %f supOff: %f subOff: %f\n", mMetrics.underlineOffset, mMetrics.underlineSize, mMetrics.strikeoutOffset, mMetrics.strikeoutSize, mMetrics.superscriptOffset, mMetrics.subscriptOffset); #endif }
int windowed_worker(int argc, char *argv[], fwin_entrypoint *fwin_main) { fwin_main1 = fwin_main; #ifdef WIN32 // The following is somewhat unsatisfactory so I will explain my options and // what is happening. // On Unix/Linux/Darwin etc I have here a single executable that, depending // on a command-line flag, runs either as a windowed or a command-line // program. All is pretty neat and convenient for me! However... // // On Windows when I link code I can link it either as subsystem:windows or // as subsystem:console. If I use the windows case then it detaches from // its console when started. The effect I have is that when launched from // a Windows command prompt asking to be run in console mode it can not // access the console. Windows XP provides an AttachConsole API that might // let me re-attach to the console but (a) that is not available with // earlier versions of Windows and (b) my experimenst with it have not been // great successes and others report delicacies! However note that even if // the code is linked as a windows binary it can be launched from the cygwin // shell and inherits standard input and output very happily! But from a // regular Windows command shell it does not. // If, on the other hand I link my code as a console application then when // launched from a command prompt or a script things work as I might like // and expect. When launched by double-clicking on an icon, Windows says to // itself "aha - a console application" and rapidly creates a console for it. // This pops up on your screen. But here (in the case I wanted a Windowed // interface) I just free that console, which then has no other users and // which therefore gets destroyed. So there is a visual glitch of an unwanted // console window popping up and instantly vanishing. // // The best solution that appears to be open to me under Windows is to // have two executable versions for each application. They would only need // to differ in the way they were linked (and hence, possibly, by one bit in // a header record in them!). One for console and one for windowed use. // That feels clumsy too. // // Web searches show that others have found the same sort of pain when they // have wanted to create applications that are both console and window // mode. Ah well. One final suggestion for the two-executable scheme is // to creats two executables, say cslw.exe and cslc.exe where cslw.exe is // linked in windows mode and cslc.exe in console mode. cslc.exe just // creates a process to run cslw.exe. When you do this the handles on // standard input and output can be inherited by the child process, which // can therefore read and write characters. However because it still does not // really have a CONSOLE it can not do the res of what one might like by way // of supporting curses-like screen updates. A final trick on this is to // rename those two programs as csl.exe (windowed) and csl.com (console). // The Windows command processor will use the ".com" extension before the // ".exe" one, but of course the executable is really in ".exe" format... // this trick maybe reduces the confusion over file-names! Or maybe it // makes it worse. #ifdef KEEP_CONSOLE_OPEN // I sometimes find a console REALLY useful for debugging.... but when you // launch by double-clicking on an icon it is truly ugly to have one around. // So I will allow myself to leave an "#ifdef" here in case that helps me make // a trick version for debugging... FreeConsole(); #endif #endif #define COMPANY_NAME "Codemist-Ltd" #define PRODUCT_NAME programName #define WINDOW_NAME programName // registry entries will be filed under Codemist-Ltd/<something>. application_object = new FXApp(PRODUCT_NAME, COMPANY_NAME); // args can be sent in via command-line args, if that is any help. // Just at present I do not fully understand what FOX does with these // arguments but it MAY be that it expects to allow "-geometry" or "-fn" // etc arguments as per standard for X11 applications. application_object->init(argc, argv, TRUE); #ifndef WIN32 debug_option = 0; for (int i=1; i<argc; i++) { if (strcmp(argv[i], "-g") == 0 || strcmp(argv[i], "-G") == 0) debug_option = 1; } /* * By default if there are any X protocol error (eg relating to missing * fonts) X send a message to stdout reporting. Unless I am in debug mode * there can be an unwanted distraction so I will hide them. If however * I am in debug mode I will set the X protocol to run in synchronous * mode, which will slow it down but make debugging easier. I believe I have * to set these options after X has been initialised and I want to do it as * soon as possible after that, hence this bit of decoding of command-line * options is separated from the main chunk. */ if (debug_option) _Xdebug = 1; else XSetErrorHandler(IgnoreXError); #endif FXRootWindow *r = application_object->getRootWindow(); rootWidth = r->getDefaultWidth(), rootHeight = r->getDefaultHeight(); // Now I will decide how big the main window should be. If I have information // in the registry left over from my last run I will use that. FXRegistry *reg = &application_object->reg(); int screenx = reg->readIntEntry("screen", "screenx", -1); int screeny = reg->readIntEntry("screen", "screeny", -1); int screenw = reg->readIntEntry("screen", "screenw", -1); int screenh = reg->readIntEntry("screen", "screenh", -1); if (screenx < 0 || screeny < 0 || screenw <= 100 || screenh < 20) { screenx = screeny = 50; // When I had 0 here that was off the screen! screenw = 0; screenh = (2*rootHeight)/3; } int fontsize = reg->readIntEntry("screen", "fontsize", -1); #if (FOX_MINOR<=4) int fontweight = reg->readIntEntry("screen", "fontweight", FONTWEIGHT_BOLD); int fontslant = reg->readIntEntry("screen", "fontslant", FONTSLANT_REGULAR); int fontencoding = reg->readIntEntry("screen", "fontencoding", FONTENCODING_DEFAULT); int fontsetwidth = reg->readIntEntry("screen", "fontsetwidth", FONTSETWIDTH_DONTCARE); int fonthints = reg->readIntEntry("screen", "fonthints", FONTPITCH_FIXED|FONTHINT_MODERN); #else int fontweight = reg->readIntEntry("screen", "fontweight", FXFont::Bold); int fontslant = reg->readIntEntry("screen", "fontslant", FXFont::Straight); int fontencoding = reg->readIntEntry("screen", "fontencoding", FONTENCODING_DEFAULT); int fontsetwidth = reg->readIntEntry("screen", "fontsetwidth", FXFont::NonExpanded); int fonthints = reg->readIntEntry("screen", "fonthints", FXFont::Fixed|FXFont::Modern); #endif const char *fontname = reg->readStringEntry("screen", "fontname", DEFAULT_FONT_NAME); // I have a concern here about how long the string that is returned will // remain valid. As a matter of caution I will not read other string values // from the registry until I have used or copied this. // The icon that I use here depends on the name that this program is // launched with. This situation in perhaps not perfect but it seems the // easiest route just for now. const unsigned char *icondata = fwin; // This sets alternative custom icons based on the name of the executable // and it clearly NOT portable... however I find it helpful, and it should // not impact anybody who wants to make independent use of this library. if (strcmp(programName, "csl") == 0) icondata = csl; else if (strcmp(programName, "bootstrapreduce") == 0) icondata = csl; else if (strcmp(programName, "reduce") == 0) icondata = reduce; main_window = new FXMainWindow1( application_object, WINDOW_NAME, new FXICOIcon(application_object, icondata, FXRGB(255,255,255), IMAGE_ALPHAGUESS), NULL, // mini-icon DECOR_ALL, screenx, screeny, screenw, screenh); main_menu_bar = new FXMenuBar(main_window, LAYOUT_SIDE_TOP | LAYOUT_FILL_X); // NB. NB. NB. // *NB* the TEXT_COLUMNWRAP flag is my own PATCH to FOX, and when I build // FOX I change the files FXText.h and FXText.cpp to implement it. It // lets me wrap lines at exactly 80 columns, regardless of how whitespace // happens to lie. text = new FXTerminal(main_window, NULL, 0, HSCROLLER_NEVER | TEXT_FIXEDWRAP | TEXT_WORDWRAP | TEXT_COLUMNWRAP | TEXT_SHOWACTIVE | LAYOUT_FILL_X | LAYOUT_FILL_Y); // I am really supposed to destroy menus as I exit. So somewhere I need to // arrange that - or maybe I can hope that my application only closes its // window when finally terminating, and somebody will tidy up at a system // level for me. fileMenu = new FXMenuPane(main_window); new FXMenuCommand(fileMenu, "&Read...", NULL, (FXObject *)text, FXTerminal::ID_READ); new FXMenuCommand(fileMenu, "&Save...", NULL, (FXObject *)text, FXTerminal::ID_SAVE); new FXMenuCommand(fileMenu, "Save Se&lection...", NULL, (FXObject *)text, FXTerminal::ID_SAVE_SELECTION); new FXMenuCommand(fileMenu, "&Print...", NULL, (FXObject *)text, FXTerminal::ID_PRINT); new FXMenuCommand(fileMenu, "Pri&nt Selection...", NULL, (FXObject *)text, FXTerminal::ID_PRINT_SELECTION); new FXMenuCommand(fileMenu, "&Break\tCtl-C\tInterrupt", NULL, (FXObject *)text, FXTerminal::ID_BREAK); new FXMenuCommand(fileMenu, "Bac&ktrace\tCtl-G\tInterrupt/backtrace", NULL, (FXObject *)text, FXTerminal::ID_BACKTRACE); new FXMenuCommand(fileMenu, "&Pause\tCtl-S", NULL, (FXObject *)text, FXTerminal::ID_PAUSE); new FXMenuCommand(fileMenu, "&Resume\tCtl-Q", NULL, (FXObject *)text, FXTerminal::ID_RESUME); new FXMenuCommand(fileMenu, "&Stop/Go\tCtl-Z", NULL, (FXObject *)text, FXTerminal::ID_STOP); new FXMenuCommand(fileMenu, "&Discard Output\tCtl-O", NULL, (FXObject *)text, FXTerminal::ID_DISCARD); new FXMenuCommand(fileMenu, "&Quit\tCtl-\\\tQuit the application.", NULL, application_object, FXApp::ID_QUIT); // I make this F&ile not &File since alt-F will be for "move forward one // word" using emacs-like key bindings. new FXMenuTitle(main_menu_bar, "F&ile", NULL, fileMenu); editMenu = new FXMenuPane(main_window); new FXMenuCommand(editMenu, "&Cut", NULL, (FXObject *)text, FXTerminal::ID_CUT_SEL_X); new FXMenuCommand(editMenu, "C&opy", NULL, (FXObject *)text, FXTerminal::ID_COPY_SEL_X); new FXMenuCommand(editMenu, "Copy &Text", NULL, (FXObject *)text, FXTerminal::ID_COPY_SEL_TEXT_X); new FXMenuCommand(editMenu, "&Paste\tCtl-V", NULL, (FXObject *)text, FXTerminal::ID_PASTE_SEL_X); new FXMenuCommand(editMenu, "&Reinput\tCtl-^\tReinput", NULL, (FXObject *)text, FXTerminal::ID_REINPUT); new FXMenuCommand(editMenu, "Select &All", NULL, (FXObject *)text, FXText::ID_SELECT_ALL); new FXMenuCommand(editMenu, "C&lear\tCtl-L", NULL, (FXObject *)text, FXTerminal::ID_CLEAR); new FXMenuCommand(editMenu, "Re&draw\tCtl-R", NULL, (FXObject *)text, FXTerminal::ID_REDRAW); new FXMenuCommand(editMenu, "&Home", NULL, (FXObject *)text, FXTerminal::ID_HOME); new FXMenuCommand(editMenu, "&End", NULL, (FXObject *)text, FXTerminal::ID_END); new FXMenuCommand(editMenu, "&Font...", NULL, (FXObject *)text, FXTerminal::ID_FONT); new FXMenuCommand(editMenu, "&Reset Font", NULL, (FXObject *)text, FXTerminal::ID_RESET_FONT); new FXMenuCommand(editMenu, "Reset &Window", NULL, (FXObject *)text, FXTerminal::ID_RESET_WINDOW); new FXMenuTitle(main_menu_bar, "&Edit", NULL, editMenu); // Add the special Reduce menus... { const char **red = reduceMenus, *p; char curTop[32], topName[32], subName[64], *q; curTop[0] = 0; reduceMenu = NULL; while (*red != NULL) { p = *red++; //@@ printf("p=%s\n", p); q = topName; while (*p != '@') *q++ = *p++; *q = 0; p++; q = subName; while (*p != '@') *q++ = *p++; *q = 0; //@@ printf("%s : %s\n", topName, subName); // Do I now have a new top-level menu name? if (strcmp(topName, curTop) != 0) { if (reduceMenu != NULL) { new FXMenuTitle(main_menu_bar, curTop, NULL, reduceMenu); //@@ printf("put %s at top\n", curTop); } reduceMenu = new FXMenuPane(main_window); strcpy(curTop, topName); //@@ printf("create new sub-menu for %s\n", curTop); } // Add a sub-menu item //@@ printf("Add in %s\n", subName); new FXMenuCommand(reduceMenu, subName, NULL, (FXObject *)text, FXTerminal::ID_REDUCE); } // The final top-level menu now needs setting up. //@@ printf("final top level item is %s\n", curTop); new FXMenuTitle(main_menu_bar, curTop, NULL, reduceMenu); } //@@ printf("Menus should be OK now\n"); helpMenu = new FXMenuPane(main_window); new FXMenuCommand(helpMenu, "&Help\tF1\tHelp", NULL, (FXObject *)text, FXTerminal::ID_HELP); #ifndef WIN32 #if !defined MACINTOSH || !defined MAC_FRAMEWORK new FXMenuCommand(helpMenu, "&Select Browser\t\tSelect Browser", NULL, (FXObject *)text, FXTerminal::ID_BROWSER); #endif #endif new FXMenuCommand(helpMenu, "&About\t\tAbout", NULL, (FXObject *)text, FXTerminal::ID_ABOUT); new FXMenuTitle(main_menu_bar, "Help", NULL, helpMenu, LAYOUT_RIGHT); text->setEditable(FALSE); text->setStyled(TRUE); text->argc = argc; text->argv = argv; strcpy(mid_stuff, programName); main_window->setTitle(programName); application_object->create(); // Selecting the font may involve measuring font sizes etc which may // need the font creating... FXFont *font1 = selectFont(fontname, fontsize, fontweight, fontslant, fontencoding, fontsetwidth, fonthints); font1->create(); text->setFont(font1); if (screenw == 0) text->onCmdResetWindow(NULL, 0, NULL); // // I will iconify the window AFTER I have adjusted its size since I do not // want to end up with a size that is silly and based on just an icon! // Also somewhere (and I now do not remember where) I picked up the idea // that minimizing twice over was a good idea... // if (windowed < 0) { main_window->minimize(); main_window->minimize(); } text->setupShowMath(); main_window->show(); text->onCmdHome(NULL, 0, NULL); // actually just to grab the focus! #ifdef WIN32 DWORD threadId; thread1 = CreateThread(NULL, // security attributes 0, // stack size worker_thread, (void *)text, 0, // flags &threadId); // Essential for Me/98/95 if (thread1 == NULL) { fprintf(stderr, "Fatal error attempting to create a thread\n"); application_object->exit(1); exit(1); } #else if (pthread_create(&thread1, NULL, worker_thread, (void *)text)) { fprintf(stderr, "Fatal error attempting to create a thread\n"); application_object->exit(1); exit(1); } #endif // Once a second I will try to flush any output buffers. But do not start // that until everything else is more or less going! application_object->addTimeout((FXObject *)text, FXTerminal::ID_TIMEOUT, 1000, NULL); if (windowed >= 0) main_window->raise(); // Bring to top. return application_object->run(); }
MsgGen::MsgGen(CToolCustom *parent, Message *msg) : QObject(parent) { m_client = msg->client(); m_edit = NULL; for (QWidget *p = parent->parentWidget(); p; p = p->parentWidget()){ if (p->inherits("MsgEdit")){ m_edit = static_cast<MsgEdit*>(p); break; } } connect(m_edit->m_userWnd, SIGNAL(multiplyChanged()), this, SLOT(textChanged())); parent->setText(i18n(" ")); m_edit->m_edit->setTextFormat(RichText); QString text = msg->getRichText(); if (!text.isEmpty()){ m_edit->m_edit->setText(text); m_edit->m_edit->moveCursor(QTextEdit::MoveEnd, false); if ((msg->getBackground() != msg->getForeground()) && !CorePlugin::m_plugin->getOwnColors()){ m_edit->m_edit->setBackground(msg->getBackground()); m_edit->m_edit->setForeground(msg->getForeground()); } } Command cmd; cmd->id = CmdSend; cmd->param = m_edit; Event e(EventCommandWidget, cmd); btnSend = (QToolButton*)(e.process()); QToolButton *btn = new ColorToolButton(parent, QColor(CorePlugin::m_plugin->getEditBackground())); set_button(btn, "bgcolor", I18N_NOOP("Bac&kground color")); connect(btn, SIGNAL(colorChanged(QColor)), this, SLOT(bgColorChanged(QColor))); parent->addWidget(btn); btn->show(); btn = new ColorToolButton(parent, QColor(CorePlugin::m_plugin->getEditForeground())); set_button(btn, "fgcolor", I18N_NOOP("&Text color")); connect(btn, SIGNAL(colorChanged(QColor)), this, SLOT(fgColorChanged(QColor))); parent->addWidget(btn); btn->show(); btnBold = new QToolButton(parent); set_button(btnBold, "text_bold", I18N_NOOP("&Bold")); btnBold->setToggleButton(true); connect(btnBold, SIGNAL(toggled(bool)), this, SLOT(toggleBold(bool))); parent->addWidget(btnBold); btnBold->show(); btnItalic = new QToolButton(parent); set_button(btnItalic, "text_italic", I18N_NOOP("&Italic")); btnItalic->setToggleButton(true); connect(btnItalic, SIGNAL(toggled(bool)), this, SLOT(toggleItalic(bool))); parent->addWidget(btnItalic); btnItalic->show(); btnUnderline = new QToolButton(parent); set_button(btnUnderline, "text_under", I18N_NOOP("&Underline")); btnUnderline->setToggleButton(true); connect(btnUnderline, SIGNAL(toggled(bool)), this, SLOT(toggleUnderline(bool))); parent->addWidget(btnUnderline); btnUnderline->show(); btn = new QToolButton(parent); set_button(btn, "text", I18N_NOOP("Text &font")); connect(btn, SIGNAL(clicked()), this, SLOT(selectFont())); parent->addWidget(btn); btn->show(); connect(m_edit->m_edit, SIGNAL(currentFontChanged(const QFont&)), this, SLOT(fontChanged(const QFont&))); connect(m_edit->m_edit, SIGNAL(textChanged()), this, SLOT(textChanged())); fontChanged(m_edit->m_edit->font()); textChanged(); }
void gfxGDIFont::Initialize() { NS_ASSERTION(!mMetrics, "re-creating metrics? this will leak"); LOGFONTW logFont; // Figure out if we want to do synthetic oblique styling. GDIFontEntry* fe = static_cast<GDIFontEntry*>(GetFontEntry()); bool wantFakeItalic = (mStyle.style & (NS_FONT_STYLE_ITALIC | NS_FONT_STYLE_OBLIQUE)) && !fe->IsItalic(); // If the font's family has an actual italic face (but font matching // didn't choose it), we have to use a cairo transform instead of asking // GDI to italicize, because that would use a different face and result // in a possible glyph ID mismatch between shaping and rendering. // // We use the mFamilyHasItalicFace flag in the entry in case of user fonts, // where the *CSS* family may not know about italic faces that are present // in the *GDI* family, and which GDI would use if we asked it to perform // the "italicization". bool useCairoFakeItalic = wantFakeItalic && fe->mFamilyHasItalicFace; if (mAdjustedSize == 0.0) { mAdjustedSize = mStyle.size; if (mStyle.sizeAdjust != 0.0 && mAdjustedSize > 0.0) { // to implement font-size-adjust, we first create the "unadjusted" font FillLogFont(logFont, mAdjustedSize, wantFakeItalic && !useCairoFakeItalic); mFont = ::CreateFontIndirectW(&logFont); // initialize its metrics so we can calculate size adjustment Initialize(); // calculate the properly adjusted size, and then proceed // to recreate mFont and recalculate metrics gfxFloat aspect = mMetrics->xHeight / mMetrics->emHeight; mAdjustedSize = mStyle.GetAdjustedSize(aspect); // delete the temporary font and metrics ::DeleteObject(mFont); mFont = nullptr; delete mMetrics; mMetrics = nullptr; } } // (bug 724231) for local user fonts, we don't use GDI's synthetic bold, // as it could lead to a different, incompatible face being used // but instead do our own multi-striking if (mNeedsBold && GetFontEntry()->IsLocalUserFont()) { mApplySyntheticBold = true; } // this may end up being zero mAdjustedSize = ROUND(mAdjustedSize); FillLogFont(logFont, mAdjustedSize, wantFakeItalic && !useCairoFakeItalic); mFont = ::CreateFontIndirectW(&logFont); mMetrics = new gfxFont::Metrics; ::memset(mMetrics, 0, sizeof(*mMetrics)); AutoDC dc; SetGraphicsMode(dc.GetDC(), GM_ADVANCED); AutoSelectFont selectFont(dc.GetDC(), mFont); // Get font metrics if size > 0 if (mAdjustedSize > 0.0) { OUTLINETEXTMETRIC oMetrics; TEXTMETRIC& metrics = oMetrics.otmTextMetrics; if (0 < GetOutlineTextMetrics(dc.GetDC(), sizeof(oMetrics), &oMetrics)) { mMetrics->superscriptOffset = (double)oMetrics.otmptSuperscriptOffset.y; // Some fonts have wrong sign on their subscript offset, bug 410917. mMetrics->subscriptOffset = fabs((double)oMetrics.otmptSubscriptOffset.y); mMetrics->strikeoutSize = (double)oMetrics.otmsStrikeoutSize; mMetrics->strikeoutOffset = (double)oMetrics.otmsStrikeoutPosition; mMetrics->underlineSize = (double)oMetrics.otmsUnderscoreSize; mMetrics->underlineOffset = (double)oMetrics.otmsUnderscorePosition; const MAT2 kIdentityMatrix = { {0, 1}, {0, 0}, {0, 0}, {0, 1} }; GLYPHMETRICS gm; DWORD len = GetGlyphOutlineW(dc.GetDC(), PRUnichar('x'), GGO_METRICS, &gm, 0, nullptr, &kIdentityMatrix); if (len == GDI_ERROR || gm.gmptGlyphOrigin.y <= 0) { // 56% of ascent, best guess for true type mMetrics->xHeight = ROUND((double)metrics.tmAscent * DEFAULT_XHEIGHT_FACTOR); } else { mMetrics->xHeight = gm.gmptGlyphOrigin.y; } mMetrics->emHeight = metrics.tmHeight - metrics.tmInternalLeading; gfxFloat typEmHeight = (double)oMetrics.otmAscent - (double)oMetrics.otmDescent; mMetrics->emAscent = ROUND(mMetrics->emHeight * (double)oMetrics.otmAscent / typEmHeight); mMetrics->emDescent = mMetrics->emHeight - mMetrics->emAscent; if (oMetrics.otmEMSquare > 0) { mFUnitsConvFactor = float(mAdjustedSize / oMetrics.otmEMSquare); } } else { // Make a best-effort guess at extended metrics // this is based on general typographic guidelines // GetTextMetrics can fail if the font file has been removed // or corrupted recently. BOOL result = GetTextMetrics(dc.GetDC(), &metrics); if (!result) { NS_WARNING("Missing or corrupt font data, fasten your seatbelt"); mIsValid = false; memset(mMetrics, 0, sizeof(*mMetrics)); return; } mMetrics->xHeight = ROUND((float)metrics.tmAscent * DEFAULT_XHEIGHT_FACTOR); mMetrics->superscriptOffset = mMetrics->xHeight; mMetrics->subscriptOffset = mMetrics->xHeight; mMetrics->strikeoutSize = 1; mMetrics->strikeoutOffset = ROUND(mMetrics->xHeight * 0.5f); // 50% of xHeight mMetrics->underlineSize = 1; mMetrics->underlineOffset = -ROUND((float)metrics.tmDescent * 0.30f); // 30% of descent mMetrics->emHeight = metrics.tmHeight - metrics.tmInternalLeading; mMetrics->emAscent = metrics.tmAscent - metrics.tmInternalLeading; mMetrics->emDescent = metrics.tmDescent; } mMetrics->internalLeading = metrics.tmInternalLeading; mMetrics->externalLeading = metrics.tmExternalLeading; mMetrics->maxHeight = metrics.tmHeight; mMetrics->maxAscent = metrics.tmAscent; mMetrics->maxDescent = metrics.tmDescent; mMetrics->maxAdvance = metrics.tmMaxCharWidth; mMetrics->aveCharWidth = NS_MAX<gfxFloat>(1, metrics.tmAveCharWidth); // The font is monospace when TMPF_FIXED_PITCH is *not* set! // See http://msdn2.microsoft.com/en-us/library/ms534202(VS.85).aspx if (!(metrics.tmPitchAndFamily & TMPF_FIXED_PITCH)) { mMetrics->maxAdvance = mMetrics->aveCharWidth; } // Cache the width of a single space. SIZE size; GetTextExtentPoint32W(dc.GetDC(), L" ", 1, &size); mMetrics->spaceWidth = ROUND(size.cx); // Cache the width of digit zero. // XXX MSDN (http://msdn.microsoft.com/en-us/library/ms534223.aspx) // does not say what the failure modes for GetTextExtentPoint32 are - // is it safe to assume it will fail iff the font has no '0'? if (GetTextExtentPoint32W(dc.GetDC(), L"0", 1, &size)) { mMetrics->zeroOrAveCharWidth = ROUND(size.cx); } else { mMetrics->zeroOrAveCharWidth = mMetrics->aveCharWidth; } mSpaceGlyph = 0; if (metrics.tmPitchAndFamily & TMPF_TRUETYPE) { WORD glyph; DWORD ret = GetGlyphIndicesW(dc.GetDC(), L" ", 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS); if (ret != GDI_ERROR && glyph != 0xFFFF) { mSpaceGlyph = glyph; } } SanitizeMetrics(mMetrics, GetFontEntry()->mIsBadUnderlineFont); } if (IsSyntheticBold()) { mMetrics->aveCharWidth += GetSyntheticBoldOffset(); mMetrics->maxAdvance += GetSyntheticBoldOffset(); } mFontFace = cairo_win32_font_face_create_for_logfontw_hfont(&logFont, mFont); cairo_matrix_t sizeMatrix, ctm; cairo_matrix_init_identity(&ctm); cairo_matrix_init_scale(&sizeMatrix, mAdjustedSize, mAdjustedSize); if (useCairoFakeItalic) { // Skew the matrix to do fake italic if it wasn't already applied // via the LOGFONT double skewfactor = OBLIQUE_SKEW_FACTOR; cairo_matrix_t style; cairo_matrix_init(&style, 1, //xx 0, //yx -1 * skewfactor, //xy 1, //yy 0, //x0 0); //y0 cairo_matrix_multiply(&sizeMatrix, &sizeMatrix, &style); } cairo_font_options_t *fontOptions = cairo_font_options_create(); if (mAntialiasOption != kAntialiasDefault) { cairo_font_options_set_antialias(fontOptions, GetCairoAntialiasOption(mAntialiasOption)); } mScaledFont = cairo_scaled_font_create(mFontFace, &sizeMatrix, &ctm, fontOptions); cairo_font_options_destroy(fontOptions); if (!mScaledFont || cairo_scaled_font_status(mScaledFont) != CAIRO_STATUS_SUCCESS) { #ifdef DEBUG char warnBuf[1024]; sprintf(warnBuf, "Failed to create scaled font: %s status: %d", NS_ConvertUTF16toUTF8(mFontEntry->Name()).get(), mScaledFont ? cairo_scaled_font_status(mScaledFont) : 0); NS_WARNING(warnBuf); #endif mIsValid = false; } else { mIsValid = true; } #if 0 printf("Font: %p (%s) size: %f adjusted size: %f valid: %s\n", this, NS_ConvertUTF16toUTF8(GetName()).get(), mStyle.size, mAdjustedSize, (mIsValid ? "yes" : "no")); printf(" emHeight: %f emAscent: %f emDescent: %f\n", mMetrics->emHeight, mMetrics->emAscent, mMetrics->emDescent); printf(" maxAscent: %f maxDescent: %f maxAdvance: %f\n", mMetrics->maxAscent, mMetrics->maxDescent, mMetrics->maxAdvance); printf(" internalLeading: %f externalLeading: %f\n", mMetrics->internalLeading, mMetrics->externalLeading); printf(" spaceWidth: %f aveCharWidth: %f xHeight: %f\n", mMetrics->spaceWidth, mMetrics->aveCharWidth, mMetrics->xHeight); printf(" uOff: %f uSize: %f stOff: %f stSize: %f supOff: %f subOff: %f\n", mMetrics->underlineOffset, mMetrics->underlineSize, mMetrics->strikeoutOffset, mMetrics->strikeoutSize, mMetrics->superscriptOffset, mMetrics->subscriptOffset); #endif }
connect( ui->actionDeselect , SIGNAL(triggered()) , this , SLOT(deselect()) ); //copy-paste connect( ui->actionCopy , SIGNAL(triggered()) , this , SLOT(copy()) ); connect( ui->actionCut , SIGNAL(triggered()) , this , SLOT(cut()) ); connect( ui->actionPaste , SIGNAL(triggered()) , this , SLOT(paste()) ); //tools connect( ui->actionIndent , SIGNAL(triggered()) , this , SLOT(indent()) ); connect( ui->actionUnindent , SIGNAL(triggered()) , this , SLOT(unindent()) ); connect( ui->actionUppercase , SIGNAL(triggered()) , this , SLOT(uppercase()) ); connect( ui->actionLowercase , SIGNAL(triggered()) , this , SLOT(lowercase()) ); connect( ui->actionCapitalize , SIGNAL(triggered()) , this , SLOT(capitalize()) ); //settings connect( ui->actionSelect_Font , SIGNAL(triggered()) , this , SLOT(selectFont()) ); connect( ui->actionSelect_Font_Color , SIGNAL(triggered()) , this , SLOT(selectFontColor()) ); connect( ui->actionZoom_In , SIGNAL(triggered()) , this , SLOT(zoomIn()) ); connect( ui->actionZoom_Out , SIGNAL(triggered()) , this , SLOT(zoomOut()) ); } MainWindow::~MainWindow() { delete ui; } void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) {