Esempio n. 1
0
//
// AbiGoogle_invoke
// -------------------
//   This is the function that we actually call to invoke the on-line dictionary.
//   It should be called when the user selects from the context menu
//
static bool 
AbiGoogle_invoke(AV_View* /*v*/, EV_EditMethodCallData * /*d*/)
{
  // Get the current view that the user is in.
  XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();
  FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView());
  
  // If the user is on a word, but does not have it selected, we need
  // to go ahead and select that word so that the search/replace goes
  // correctly.
  if (pView->isSelectionEmpty()) {
    pView->moveInsPtTo(FV_DOCPOS_EOW_MOVE);
    pView->moveInsPtTo(FV_DOCPOS_BOW);
    pView->extSelTo(FV_DOCPOS_EOW_SELECT);   
  }

  // Now we will figure out what word to look up
  UT_UTF8String url ("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=");
  
  // url escaping should be moved somewhere more generic
  UT_UCS4Char *ucs4ST;
  pView->getSelectionText(*&ucs4ST);
  UT_UCS4String data (ucs4ST);
  bool last_was_space = false;
  for (size_t i = 0; i < data.length (); i++) {
    UT_UCS4Char ch = data[i];
    if (!UT_UCS4_isspace (ch)) {
      url.appendUCS4 (&ch, 1);
      last_was_space = false;
    }
    else if (!last_was_space) {
      ch = '+';
      url.appendUCS4 (&ch, 1);
      last_was_space = true;
    }
  }

  XAP_App::getApp()->openURL( url.utf8_str() ); 
  FREEP(ucs4ST);

  return true;
}
Esempio n. 2
0
/*!  
 * Get all character-related attributes and append them to props.
 *
 * If props is not empty, we start with '; ', else we do not.
 */
UT_Error IE_Imp_Psion::getCharacterAttributes(const psiconv_character_layout layout,
                                             UT_UTF8String &props)
{
	UT_return_val_if_fail(layout != NULL, true /* perhaps should be false, but we want loading to proceed */);

	UT_UTF8String buffer;
	int fontsize;
	UT_UCS4Char ucs4char;
	int i;

	// Append a semicolon if there is already text in the props
	if (props.length())
		props += "; ";
		
	// font family
	// BUG: No checking is done yet whether this family is known to AbiWord.
	// We need to sanitize the font name first, or we could confuse the
	// properties parser.
	props += "font-family:";
	for (i = 0; i < psiconv_unicode_strlen(layout->font->name); i++) {
		ucs4char = layout->font->name[i];
		if ((ucs4char < 0x20) || (ucs4char == ';') || (ucs4char == ':'))
			ucs4char = '?';
		props.appendUCS4(&ucs4char,1);
	}
	
	// font size.
	// This should be moved to some general-purpose function.
	// At the moment, only the following font-sizes seem to be supported
	// by the GUI: 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
	// 36, 48 and 72. Others give GTK errors. This should be changed I think.
	fontsize = (int) layout->font_size;
	if (fontsize < 8)
		fontsize = 8;
	if ((fontsize % 2) && (fontsize > 11))
		fontsize -=1;
	if (fontsize > 28) {
		if (fontsize < 32)
			fontsize = 28;
		else if (fontsize < 42)
			fontsize = 36;
		else if (fontsize < 60)
			fontsize = 48;
		else
			fontsize = 72;
	}
	UT_UTF8String_sprintf(buffer,"; font-size:%dpt",fontsize);
	props += buffer;
	
	// bold
	UT_UTF8String_sprintf(buffer, "; font-weight:%s", layout->bold ? "bold" : "normal");
	props += buffer;
	
	// italic
	UT_UTF8String_sprintf(buffer, "; font-style:%s",layout->italic ? "italic" : "normal");
	props += buffer;
	
	// underline and strike-through
	UT_UTF8String_sprintf(buffer, "; text-decoration:%s",
	        layout->underline && layout->strikethrough?"underline line-through":
	        layout->underline && !layout->strikethrough?"underline":
	        !layout->underline && layout->strikethrough?"line-through":
		                                                "none");
	props += buffer;
	
	// superscript and subscript
	UT_UTF8String_sprintf(buffer, "; text-position:%s",
	       layout->super_sub == psiconv_superscript?"superscript":
	       layout->super_sub == psiconv_subscript  ?"subscript":
		                                            "normal");
	props += buffer;
	
	// text color
	UT_UTF8String_sprintf(buffer, "; color:%02x%02x%02x", (layout->color->red),
	                                        (layout->color->green),
	                                        (layout->color->blue));
	props += buffer;
	
	// background color
	UT_UTF8String_sprintf(buffer, "; bgcolor:%02x%02x%02x", layout->back_color->red,
	                                          layout->back_color->green,
	                                          layout->back_color->blue);
	props += buffer;
	return UT_OK;
}
Esempio n. 3
0
void s_XSL_FO_Listener::_outputData(const UT_UCSChar * data, UT_uint32 length)
{
	UT_UTF8String sBuf;
	const UT_UCSChar * pData;

	UT_ASSERT(sizeof(UT_Byte) == sizeof(char));

	sBuf.reserve(length);
	for (pData=data; (pData<data+length); /**/)
	{
		switch (*pData)
		{
			case '<':
			{
				sBuf += "&lt;";
				pData++;
				break;
			}

			case '>':
			{
				sBuf += "&gt;";
				pData++;
				break;
			}

			case '&':
			{
				sBuf += "&amp;";
				pData++;
				break;
			}

			case UCS_LF:					// LF -- representing a Forced-Line-Break
			{
				UT_ASSERT(UT_TODO);
				pData++;
				break;
			}

			case UCS_VTAB:					// VTAB -- representing a Forced-Column-Break
			{
				UT_ASSERT(UT_TODO);
				pData++;
				break;
			}

			case UCS_FF:					// FF -- representing a Forced-Page-Break
			{
				UT_ASSERT(UT_TODO);
				pData++;
				break;
			}

			default:
			{
				if(*pData < 0x20)  //invalid xml chars
				{
					pData++;
				}
				else
				{
					sBuf.appendUCS4(pData, 1);
					pData++;
				}
				break;
			}
		}
	}

	m_pie->write(sBuf.utf8_str(), sBuf.byteLength());
}
bool fp_FieldTableSumCols::calculateValue(void)
{
	FV_View * pView = _getView();
	pf_Frag_Strux* tableSDH= NULL;
	UT_sint32 numRows =0;
	UT_sint32 numCols = 0;
	bUseCurrency = false;
	cCurrency = '$';
	pf_Frag_Strux* sdh = getBlock()->getStruxDocHandle();
	PD_Document * pDoc = getBlock()->getDocument();
	if(pDoc->isPieceTableChanging())
	{
		return false;
	}
	if(getLine() == NULL)
	{
		return false;
	}
	fp_Container * pCol = getLine()->getColumn();
	if(pCol == NULL)
	{
		return false;
	}
	fp_ShadowContainer * pShad =NULL;
	fl_HdrFtrShadow * pShadL = NULL;
	if(pCol->getContainerType() == FP_CONTAINER_COLUMN_SHADOW)
	{
		pShad = static_cast<fp_ShadowContainer *>(pCol);
		pShadL = pShad->getShadow();
	}
	PT_DocPosition pos = pDoc->getStruxPosition(sdh)+1;
	pDoc->getStruxOfTypeFromPosition(pos,PTX_SectionTable,&tableSDH);
	pDoc-> getRowsColsFromTableSDH(tableSDH, pView->isShowRevisions(), pView->getRevisionLevel(), &numRows, &numCols);

	UT_UTF8String sValF;
	if(!pView->isInTable(pos))
	{
		sValF = "???";
		return _setValue(sValF.ucs4_str().ucs4_str());
	}

	fl_CellLayout * pCell = NULL;
	UT_sint32 myLeft,myRight,myTop,myBot;
	pView->getCellParams(pos,&myLeft,&myRight,&myTop,&myBot);
	UT_sint32 col = 0;
	UT_sint32 row = myTop;
	UT_sint32 lastCol = -1;
	double dSum = 0.0;
	for(col = 0; col < numCols; col++)
	{
		pf_Frag_Strux* sdhCell = pDoc->getCellSDHFromRowCol(tableSDH,true,99999,row,col);
		UT_sint32 i = getBlock()->getDocLayout()->getLID();
		fl_ContainerLayout* fmtCell = pDoc->getNthFmtHandle(sdhCell,i);
		pCell = static_cast<fl_CellLayout *>(fmtCell);
		if(pCell->getLeftAttach() == lastCol)
		{
			continue;
		}
		if((pCell->getTopAttach() == myTop) && (pCell->getLeftAttach() == myLeft))
		{
			continue;
		}
		UT_GrowBuf grText;
		pCell->appendTextToBuf(grText);
		if(grText.getLength() == 0)
		{
			fl_ContainerLayout * pC = pCell->getFirstLayout();
			while(pC)
			{
				if(pC->getContainerType() == FL_CONTAINER_BLOCK)
				{
					fl_BlockLayout * pBL = static_cast<fl_BlockLayout *>(pC);
					if(pShadL)
					{
						pBL = static_cast<fl_BlockLayout *>(pShadL->findMatchingContainer(pBL));
					}
					if(pBL == NULL)
					{
						continue;
					}
					fp_Run * pRun = pBL->getFirstRun();
					while(pRun)
					{
						if(pRun->getType() == FPRUN_FIELD)
						{
							fp_FieldRun * pFRun = static_cast<fp_FieldRun *>(pRun);
							const  UT_UCS4Char * szVal = pFRun->getValue(); 
							sValF.clear();
							sValF.appendUCS4(szVal);
							dSum += dGetVal(sValF.utf8_str());
							pRun = NULL;
							pC = NULL;
							break;
						}
						pRun = pRun->getNextRun();
					}
				}
				if(pC)
				{
					pC = pC->getNext();
				}
			}
		}
		else
		{
			sValF.clear();
			sValF.appendUCS4(reinterpret_cast<const UT_UCS4Char *>(grText.getPointer(0)),grText.getLength());
			dSum += dGetVal(sValF.utf8_str());
		}
		lastCol = col;
	}
	sFormatDouble(sValF,dSum);
	return _setValue(sValF.ucs4_str().ucs4_str());
}
Esempio n. 5
0
void ODe_AbiDocListener::_outputData(const UT_UCSChar* pData, UT_uint32 length) {
    UT_UTF8String sBuf;
    const UT_UCSChar* p;
    UT_uint32 nSpaces = 0;

    UT_ASSERT(sizeof(UT_Byte) == sizeof(char));
    sBuf.reserve(length);

    for (p=pData; (p<pData+length); /**/)
    {
        switch (*p)
        {
        case '<':
            if(nSpaces > 1)
                _appendSpaces(&sBuf, nSpaces);
            nSpaces = 0;

            sBuf += "&lt;";
            p++;
            break;

        case '>':
            if(nSpaces > 1)
                _appendSpaces(&sBuf, nSpaces);
            nSpaces = 0;

            sBuf += "&gt;";
            p++;
            break;

        case '&':
            if(nSpaces > 1)
                _appendSpaces(&sBuf, nSpaces);
            nSpaces = 0;

            sBuf += "&amp;";
            p++;
            break;

        case ' ':
            nSpaces++;

            if(nSpaces == 1)
                sBuf.appendUCS4 (p, 1);

            p++;
            break;

        case UCS_LF:               // LF -- representing a Forced-Line-Break
            if(nSpaces > 1)
                _appendSpaces(&sBuf, nSpaces);
            nSpaces = 0;

            m_pCurrentImpl->insertText(sBuf);
            m_pCurrentImpl->insertLineBreak();
            sBuf.clear();
            p++;
            break;

        case UCS_VTAB:             // VTAB -- representing a Forced-Column-Break
            if(nSpaces > 1)
                _appendSpaces(&sBuf, nSpaces);
            nSpaces = 0;

            m_pCurrentImpl->insertText(sBuf);
            m_pCurrentImpl->insertColumnBreak();
            sBuf.clear();
            p++;
            break;

        case UCS_TAB:
            if(nSpaces > 1)
                _appendSpaces(&sBuf, nSpaces);
            nSpaces = 0;

			m_pCurrentImpl->insertText(sBuf);
			m_pCurrentImpl->insertTabChar();
			sBuf.clear();
            p++;
            break;

        case UCS_FF:               // FF -- representing a Forced-Page-Break
            if(nSpaces > 1)
                _appendSpaces(&sBuf, nSpaces);
            nSpaces = 0;

            m_pCurrentImpl->insertText(sBuf);
            m_pCurrentImpl->insertPageBreak();
            sBuf.clear();
            p++;
            break;

        default:
            if (*p < 0x20)         // Silently eat these characters.
            {
                if(nSpaces > 1)
                    _appendSpaces(&sBuf, nSpaces);
                nSpaces = 0;
                p++;
            }
            else
            {
                if(nSpaces > 1)
                    _appendSpaces(&sBuf, nSpaces);
                nSpaces = 0;

                sBuf.appendUCS4 (p, 1);
                p++;
            }
        }
    }

    if (!sBuf.empty()) {
        if(nSpaces > 1)
            _appendSpaces(&sBuf, nSpaces);
        nSpaces = 0;
        m_pCurrentImpl->insertText(sBuf);
    }
}