static bool _convertBorderThickness(const char* szIncoming, UT_UTF8String& sConverted) { UT_return_val_if_fail(szIncoming && *szIncoming, false); double d = 0.0f; UT_Dimension units = UT_determineDimension (szIncoming, DIM_none); if (units == DIM_none) { // no (valid) dimension specified, we'll assume inches d = UT_convertToInches(szIncoming); d = UT_convertInchesToDimension(d, DIM_PT); } else { d = UT_convertToPoints(szIncoming); } UT_LocaleTransactor t(LC_NUMERIC, "C"); sConverted = UT_UTF8String_sprintf("%.2fpt", d); return true; }
static UT_UTF8String s_canonical_thickness (const UT_UTF8String & sThickness, float & thickness) { thickness = static_cast<float>(UT_convertToPoints(sThickness.utf8_str())); UT_UTF8String sThick; if (thickness < 0.01) { thickness = 0.01f; sThick = "0.01pt"; } else if (thickness > 99.99) { thickness = 99.99f; sThick = "99.99pt"; } else { char buf[16]; UT_LocaleTransactor t(LC_NUMERIC, "C"); sprintf(buf, "%.2fpt", thickness); sThick = buf; } return sThick; }
void XAP_UnixDialog_FontChooser::runModal(XAP_Frame * pFrame) { m_pFrame = static_cast<XAP_Frame *>(pFrame); // used similarly to convert between text and numeric arguments static char sizeString[50]; // build the dialog GtkWidget * cf = constructWindow(); // freeze updates of the preview m_blockUpdate = true; // to sort out dupes std::set<std::string> fontSet; GtkTreeModel* model; GtkTreeIter iter; model = gtk_tree_view_get_model(GTK_TREE_VIEW(m_fontList)); gtk_list_store_clear(GTK_LIST_STORE(model)); GR_GraphicsFactory * pGF = XAP_App::getApp()->getGraphicsFactory(); if(!pGF) { return; } const std::vector<std::string> & names = GR_CairoGraphics::getAllFontNames(); for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) { const std::string & fName = *i; if (fontSet.find(fName) == fontSet.end()) { fontSet.insert(fName); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN, fName.c_str(), -1); } } // Set the defaults in the list boxes according to dialog data gint foundAt = 0; const std::string sFontFamily = getVal("font-family"); foundAt = searchTreeView(GTK_TREE_VIEW(m_fontList), sFontFamily.c_str()); // select and scroll to font name if (foundAt >= 0) { GtkTreePath* path = gtk_tree_path_new_from_indices(foundAt, -1); gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_fontList), path, NULL, FALSE); gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_fontList), path, NULL, TRUE, 0.5 , 0.0); gtk_tree_path_free(path); } // this is pretty messy listStyle st = LIST_STYLE_NORMAL; const std::string sWeight = getVal("font-weight"); const std::string sStyle = getVal("font-style"); if (sStyle.empty() || sWeight.empty()) st = LIST_STYLE_NONE; else { bool isBold = !g_ascii_strcasecmp(sWeight.c_str(), "bold"); bool isItalic = !g_ascii_strcasecmp(sStyle.c_str(), "italic"); if (!isBold && !isItalic) { st = LIST_STYLE_NORMAL; } else if (!isItalic && isBold) { st = LIST_STYLE_BOLD; } else if (isItalic && !isBold) { st = LIST_STYLE_ITALIC; } else if (isItalic && isBold) { st = LIST_STYLE_BOLD_ITALIC; } else { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); } } // select and scroll to style name if (st != LIST_STYLE_NONE) { GtkTreePath* path = gtk_tree_path_new_from_indices(st, -1); gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_styleList), path, NULL, FALSE); gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_styleList), path, NULL, TRUE, 0.5 , 0.0); gtk_tree_path_free(path); } g_snprintf(sizeString, 60, "%s", std_size_string(UT_convertToPoints(getVal("font-size").c_str()))); foundAt = searchTreeView(GTK_TREE_VIEW(m_sizeList), XAP_EncodingManager::fontsizes_mapping.lookupBySource(sizeString)); // select and scroll to size name if (foundAt >= 0) { GtkTreePath* path = gtk_tree_path_new_from_indices(foundAt, -1); gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_sizeList), path, NULL, FALSE); gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_sizeList), path, NULL, TRUE, 0.5 , 0.0); gtk_tree_path_free(path); } // Set color in the color selector const std::string sColor = getVal("color"); if (!sColor.empty()) { UT_RGBColor c; UT_parseColor(sColor.c_str(), c); GdkRGBA *color = UT_UnixRGBColorToGdkRGBA(c); m_currentFGColor = *color; gdk_rgba_free(color); gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorSelector), &m_currentFGColor); } else { // if we have no color, use a placeholder of funky values // the user can't pick interactively. This catches ALL // the cases except where the user specifically enters -1 for // all Red, Green and Blue attributes manually. This user // should expect it not to touch the color. :) gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorSelector), &m_funkyColor); } // Set color in the color selector const std::string sBGCol = getVal("bgcolor"); if (!sBGCol.empty() && strcmp(sBGCol.c_str(),"transparent") != 0) { UT_RGBColor c; UT_parseColor(sBGCol.c_str(), c); GdkRGBA *color = UT_UnixRGBColorToGdkRGBA(c); m_currentBGColor = *color; gdk_rgba_free(color); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), FALSE); gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_bgcolorSelector), &m_currentBGColor); } else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), TRUE); // fix for GTK's questionable gtk_toggle_set_active behaviour (emits when setting TRUE) m_bChangedStrikeOut = m_bStrikeout; m_bChangedUnderline = m_bUnderline; m_bChangedOverline = m_bOverline; m_bChangedHidden = m_bHidden; m_bChangedSubScript = m_bSubScript; m_bChangedSuperScript = m_bSuperScript; // set the strikeout, underline, overline, and hidden check buttons gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkStrikeOut), m_bStrikeout); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkUnderline), m_bUnderline); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkOverline), m_bOverline); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkHidden), m_bHidden); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSubScript), m_bSubScript); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSuperScript), m_bSuperScript); m_doneFirstFont = true; // attach a new graphics context gtk_widget_show ( cf ) ; GR_UnixCairoAllocInfo ai(m_preview); m_gc = (GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai); GtkAllocation alloc; gtk_widget_get_allocation(m_preview, &alloc); _createFontPreviewFromGC(m_gc,alloc.width,alloc.height); // // This enables callbacks on the preview area with a widget pointer to // access this dialog. // g_object_set_data(G_OBJECT(m_preview), "user-data", this); // unfreeze updates of the preview m_blockUpdate = false; // manually trigger an update updatePreview(); switch ( abiRunModalDialog ( GTK_DIALOG(cf), pFrame, this, BUTTON_CANCEL, true ) ) { case BUTTON_OK: { m_answer = a_OK; break ; } default: { m_answer = a_CANCEL; break; } } // these dialogs are cached around through the dialog framework, // and this variable needs to get set back m_doneFirstFont = false; UT_DEBUGMSG(("FontChooserEnd: Family[%s%s] Size[%s%s] Weight[%s%s] Style[%s%s] Color[%s%s] Underline[%d%s] StrikeOut[%d%s] SubScript[%d%s] SuperScript[%d%s]\n", getVal("font-family").c_str(), ((m_bChangedFontFamily) ? "(chg)" : ""), getVal("font-size").c_str(), ((m_bChangedFontSize) ? "(chg)" : ""), getVal("font-weight").c_str(), ((m_bChangedFontWeight) ? "(chg)" : ""), getVal("font-style").c_str(), ((m_bChangedFontStyle) ? "(chg)" : ""), getVal("color").c_str(), ((m_bChangedColor) ? "(chg)" : ""), m_bUnderline, ((m_bChangedUnderline) ? "(chg)" : ""), m_bStrikeout, ((m_bChangedStrikeOut) ? "(chg)" : ""), m_bSubScript, ((m_bChangedSubScript) ? "(chg)" : ""), m_bSuperScript, ((m_bChangedSuperScript) ? "(chg)" : "") )); // answer should be set by the appropriate callback // the caller can get the answer from getAnswer(). m_pFrame = NULL; }
void WordPerfect_Listener::_openSpan(PT_AttrPropIndex api) { if (!m_bInBlock) { return; } const PP_AttrProp * pAP = NULL; bool bHaveProp = m_pDocument->getAttrProp(api,&pAP); if (bHaveProp && pAP) { const gchar * szValue; if ( (pAP->getProperty("text-position", szValue)) && !strcmp(szValue, "superscript") ) { _handleAttributeOn((char) 5); // FIXME: use defines } if ( (pAP->getProperty("text-position", szValue)) && !strcmp(szValue, "subscript") ) { _handleAttributeOn((char) 6); // FIXME: use defines } if ( (pAP->getProperty("font-style", szValue)) && !strcmp(szValue, "italic") ) { _handleAttributeOn((char) 8); // FIXME: use defines } if ( (pAP->getProperty("font-weight", szValue)) && !strcmp(szValue, "bold") ) { _handleAttributeOn((char) 12); // FIXME: use defines } if ( (pAP->getProperty("text-decoration", szValue)) ) { const gchar* pszDecor = szValue; gchar* p; if (!(p = g_strdup(pszDecor))) { // TODO outofmem } UT_return_if_fail(p || !pszDecor); gchar* q = strtok(p, " "); while (q) { if (0 == strcmp(q, "line-through")) { _handleAttributeOn((char) 13); // FIXME: use defines } q = strtok(NULL, " "); } FREEP(p); } if ( (pAP->getProperty("text-decoration", szValue)) ) { const gchar* pszDecor = szValue; gchar* p; if (!(p = g_strdup(pszDecor))) { // TODO outofmem } UT_return_if_fail(p || !pszDecor); gchar* q = strtok(p, " "); while (q) { if (0 == strcmp(q, "underline")) { _handleAttributeOn((char) 14); // FIXME: use defines } q = strtok(NULL, " "); } FREEP(p); } if ( (pAP->getProperty("color", szValue)) || (pAP->getProperty("font-size", szValue)) || (pAP->getProperty("font-family", szValue)) || (pAP->getProperty("bgcolor", szValue)) ) { const gchar* pszColor = NULL; const gchar* pszBgColor = NULL; const gchar* pszFontSize = NULL; const gchar* pszFontFamily = NULL; pAP->getProperty("color", pszColor); pAP->getProperty("font-size", pszFontSize); pAP->getProperty("font-family", pszFontFamily); pAP->getProperty("bgcolor", pszBgColor); if (pszColor) { // ... } if (pszFontSize) { UT_LocaleTransactor lt (LC_NUMERIC, "C"); _handleFontSizeChange(UT_convertToPoints(pszFontSize)); } if (pszFontFamily) { // ... } if (pszBgColor) { // ... } } m_pAP_Span = pAP; } }
void XAP_Win32Dialog_FontChooser::runModal(XAP_Frame * pFrame) { UT_return_if_fail(pFrame); XAP_Win32App * pApp = static_cast<XAP_Win32App *>(XAP_App::getApp()); UT_return_if_fail(pApp); const XAP_EncodingManager *pEncMan = pApp->getEncodingManager(); UT_return_if_fail(pEncMan); UT_Win32LocaleString family; UT_DEBUGMSG(("FontChooserStart: Family[%s] Size[%s] Weight[%s] Style[%s] Color[%s] Underline[%d] StrikeOut[%d]\n", m_sFontFamily.c_str(), m_sFontSize.c_str(), m_sFontWeight.c_str(), m_sFontStyle.c_str(), m_sColor.c_str(), m_bUnderline, m_bStrikeout)); m_bWin32Overline = m_bOverline; m_bWin32Hidden = m_bHidden; m_bWin32SuperScript = m_bSuperScript; m_bWin32SubScript = m_bSubScript; /* WARNING: any changes to this function should be closely coordinated with the equivalent logic in Win32Graphics::FindFont() */ LOGFONTW lf; memset(&lf, 0, sizeof(lf)); CHOOSEFONTW cf; memset(&cf, 0, sizeof(cf)); cf.lStructSize = sizeof(cf); cf.hwndOwner = static_cast<XAP_Win32FrameImpl*>(pFrame->getFrameImpl())->getTopLevelWindow(); cf.lpLogFont = &lf; cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK | CF_ENABLETEMPLATE | CF_INITTOLOGFONTSTRUCT; cf.lpTemplateName = MAKEINTRESOURCEW(XAP_RID_DIALOG_FONT); cf.lpfnHook = (LPCFHOOKPROC) s_hookProc; cf.lCustData = (LPARAM) this; cf.hInstance = pApp->getInstance(); if (!m_sFontFamily.empty()) { family.fromUTF8 (m_sFontFamily.c_str()); lstrcpynW(lf.lfFaceName,family.c_str(),LF_FACESIZE); } else cf.Flags |= CF_NOFACESEL; if (!m_sFontSize.empty()) { UT_ASSERT(sizeof(char) == sizeof(gchar)); lf.lfHeight = (long) -(UT_convertToPoints(m_sFontSize.c_str()))*4/3; } else cf.Flags |= CF_NOSIZESEL; if (!m_sFontWeight.empty()) { if (g_ascii_strcasecmp(m_sFontWeight.c_str(),"bold") == 0) lf.lfWeight = 700; // TODO do we need any others here... } else cf.Flags |= CF_NOSTYLESEL; if (!m_sFontStyle.empty()) { if (g_ascii_strcasecmp(m_sFontStyle.c_str(),"italic") == 0) lf.lfItalic = TRUE; } else cf.Flags |= CF_NOSTYLESEL; if (!m_sColor.empty()) { UT_RGBColor c; UT_parseColor(m_sColor.c_str(),c); cf.rgbColors = RGB(c.m_red,c.m_grn,c.m_blu); } if (m_bUnderline) lf.lfUnderline = TRUE; if (m_bStrikeout) lf.lfStrikeOut = TRUE; // run the actual dialog... m_answer = (ChooseFontW(&cf) ? a_OK : a_CANCEL); // Convert the font name returned by the Windows Font Chooser // to UTF-8. family.fromLocale (lf.lfFaceName); UT_UTF8String family_utf = family.utf8_str(); const char *szFontFamily = family_utf.utf8_str(); if (m_answer == a_OK) { if(!m_sFontFamily.empty()) { if((g_ascii_strcasecmp(szFontFamily, m_sFontFamily.c_str()) != 0)) { m_bChangedFontFamily = true; m_sFontFamily = szFontFamily; } } else { if(szFontFamily[0]) { m_bChangedFontFamily = true; m_sFontFamily = szFontFamily; } } bool bIsSizeValid = ((cf.Flags & CF_NOSIZESEL) == 0); bool bWasSizeValid = !m_sFontSize.empty(); char bufSize[10]; if (bIsSizeValid) sprintf(bufSize,"%dpt",(cf.iPointSize/10)); else bufSize[0] = 0; // why? let's see if (bIsSizeValid && (g_ascii_strcasecmp(bufSize,m_sFontSize.c_str()) != 0)) { m_bChangedFontSize = true; m_sFontSize = bufSize; } else { /* nothing changed */ } bool bIsBold = ((cf.nFontType & BOLD_FONTTYPE) != 0); bool bWasBold = (g_ascii_strcasecmp(m_sFontWeight.c_str(),"bold") == 0); bool bIsNormal = ((cf.nFontType & REGULAR_FONTTYPE) != 0); bool bWasNormal = (m_sFontWeight.empty() || (g_ascii_strcasecmp(m_sFontWeight.c_str(),"normal") != 0)); if ((bIsBold != bWasBold) || (bIsNormal != bWasNormal)) { m_bChangedFontWeight = true; if( bIsBold ) m_sFontWeight = "bold"; else m_sFontWeight = "normal"; } bool bIsItalic = ((cf.nFontType & ITALIC_FONTTYPE) != 0); bool bWasItalic = (g_ascii_strcasecmp(m_sFontStyle.c_str(),"italic") == 0); if (bIsItalic != bWasItalic) { m_bChangedFontStyle = true; if( bIsItalic ) m_sFontStyle = "italic"; else m_sFontStyle = "normal"; } char bufColor[10]; sprintf(bufColor,"%02x%02x%02x",GetRValue(cf.rgbColors), GetGValue(cf.rgbColors),GetBValue(cf.rgbColors)); bool bWasColorValid = !m_sColor.empty(); if ( m_bChangedColor && ((bWasColorValid && (g_ascii_strcasecmp(bufColor,m_sColor.c_str()) != 0)) || (!bWasColorValid && (g_ascii_strcasecmp(bufColor,"000000") != 0)))) { m_sColor = bufColor; } m_bChangedUnderline = ((lf.lfUnderline == TRUE) != m_bUnderline); m_bChangedStrikeOut = ((lf.lfStrikeOut == TRUE) != m_bStrikeout); m_bChangedOverline = (m_bWin32Overline != m_bOverline); if (m_bChangedUnderline || m_bChangedStrikeOut || m_bChangedOverline) setFontDecoration( (lf.lfUnderline == TRUE), m_bWin32Overline, (lf.lfStrikeOut == TRUE), NULL, NULL); m_bChangedHidden = (m_bWin32Hidden != m_bHidden); m_bChangedSuperScript = (m_bWin32SuperScript != m_bSuperScript); m_bChangedSubScript = (m_bWin32SubScript != m_bSubScript); if(m_bChangedHidden) setHidden(m_bWin32Hidden); if(m_bChangedSuperScript) setSuperScript(m_bWin32SuperScript); if(m_bChangedSubScript) setSubScript(m_bWin32SubScript); } UT_DEBUGMSG(("FontChooserEnd: Family[%s%s] Size[%s%s] Weight[%s%s] Style[%s%s] Color[%s%s] Underline[%d%s] StrikeOut[%d%s]\n", m_sFontFamily.c_str(), ((m_bChangedFontFamily) ? "(chg)" : ""), m_sFontSize.c_str(), ((m_bChangedFontSize) ? "(chg)" : ""), m_sFontWeight.c_str(), ((m_bChangedFontWeight) ? "(chg)" : ""), m_sFontStyle.c_str(), ((m_bChangedFontStyle) ? "(chg)" : ""), m_sColor.c_str(), ((m_bChangedColor) ? "(chg)" : ""), m_bUnderline, ((m_bChangedUnderline) ? "(chg)" : ""), m_bStrikeout, ((m_bChangedStrikeOut) ? "(chg)" : ""))); // the caller can get the answer from getAnswer(). m_pWin32Frame = NULL; }