void CXML_Parser::GetName(CFX_ByteString& space, CFX_ByteString& name) { m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; if (IsEOF()) { return; } CFX_ByteTextBuf buf; uint8_t ch; do { while (m_dwIndex < m_dwBufferSize) { ch = m_pBuffer[m_dwIndex]; if (ch == ':') { space = buf.AsStringC(); buf.Clear(); } else if (g_FXCRT_XML_IsNameChar(ch)) { buf.AppendChar(ch); } else { break; } m_dwIndex++; } m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; if (m_dwIndex < m_dwBufferSize || IsEOF()) { break; } } while (ReadNextBlock()); name = buf.AsStringC(); }
void IFX_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects, IFX_Edit* pEdit, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, FX_COLORREF crText, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { FX_FLOAT fFontSize = pEdit->GetFontSize(); int32_t nOldFontIndex = -1; CFX_ByteTextBuf sTextBuf; CPDF_Point ptBT(0.0f,0.0f); ObjArray.RemoveAll(); if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap()) { if (pRange) pIterator->SetAt(pRange->BeginPos); else pIterator->SetAt(0); CPVT_WordPlace oldplace; while (pIterator->NextWord()) { CPVT_WordPlace place = pIterator->GetAt(); if (pRange && place.WordCmp(pRange->EndPos) > 0) break; CPVT_Word word; if (pIterator->GetWord(word)) { if (place.LineCmp(oldplace) != 0 || nOldFontIndex != word.nFontIndex) { if (sTextBuf.GetLength() > 0) { ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, 0.0f, 100, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString())); sTextBuf.Clear(); } ptBT = word.ptWord; nOldFontIndex = word.nFontIndex; } sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0); oldplace = place; } } if (sTextBuf.GetLength() > 0) { ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, 0.0f, 100, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString())); } } } }
void IFX_Edit::GenerateRichPageObjects( CPDF_PageObjects* pPageObjects, IFX_Edit* pEdit, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); FX_COLORREF crOld = crCurText; CFX_ByteTextBuf sTextBuf; CPVT_WordProps wp; CPDF_Point ptBT(0.0f, 0.0f); ObjArray.RemoveAll(); if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap()) { if (pRange) pIterator->SetAt(pRange->BeginPos); else pIterator->SetAt(0); CPVT_WordPlace oldplace; while (pIterator->NextWord()) { CPVT_WordPlace place = pIterator->GetAt(); if (pRange && place.WordCmp(pRange->EndPos) > 0) break; CPVT_Word word; if (pIterator->GetWord(word)) { word.WordProps.fFontSize = word.fFontSize; crCurText = ArgbEncode(255, word.WordProps.dwWordColor); if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || word.WordProps.nHorzScale != 100 || FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 || crOld != crCurText) { if (sTextBuf.GetLength() > 0) { ObjArray.Add(AddTextObjToPageObjects( pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, wp.fCharSpace, wp.nHorzScale, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), sTextBuf.GetByteString())); sTextBuf.Clear(); } wp = word.WordProps; ptBT = word.ptWord; crOld = crCurText; } sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, word.Word, 0); if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) { /* AddLineToPageObjects(pPageObjects, crCurText, CPDF_Point(word.ptWord.x, word.ptWord.y + word.fDescent * 0.4f), CPDF_Point(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent * 0.4f)); */ CPDF_Rect rcUnderline = GetUnderLineRect(word); rcUnderline.left += ptOffset.x; rcUnderline.right += ptOffset.x; rcUnderline.top += ptOffset.y; rcUnderline.bottom += ptOffset.y; AddRectToPageObjects(pPageObjects, crCurText, rcUnderline); } if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { CPDF_Rect rcCrossout = GetCrossoutRect(word); rcCrossout.left += ptOffset.x; rcCrossout.right += ptOffset.x; rcCrossout.top += ptOffset.y; rcCrossout.bottom += ptOffset.y; AddRectToPageObjects(pPageObjects, crCurText, rcCrossout); } oldplace = place; } } if (sTextBuf.GetLength() > 0) { ObjArray.Add(AddTextObjToPageObjects( pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, wp.fCharSpace, wp.nHorzScale, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), sTextBuf.GetByteString())); } } } }
void IFX_Edit::DrawRichEdit(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit, const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange) { // FX_FLOAT fFontSize = pEdit->GetFontSize(); CPVT_WordRange wrSelect = pEdit->GetSelectWordRange(); FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); FX_COLORREF crOld = crCurText; FX_BOOL bSelect = FALSE; const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255); const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113); CFX_ByteTextBuf sTextBuf; CPVT_WordProps wp; CPDF_Point ptBT(0.0f, 0.0f); pDevice->SaveState(); if (!rcClip.IsEmpty()) { CPDF_Rect rcTemp = rcClip; pUser2Device->TransformRect(rcTemp); FX_RECT rcDevClip; rcDevClip.left = (int32_t)rcTemp.left; rcDevClip.right = (int32_t)rcTemp.right; rcDevClip.top = (int32_t)rcTemp.top; rcDevClip.bottom = (int32_t)rcTemp.bottom; pDevice->SetClip_Rect(&rcDevClip); } if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap()) { if (pRange) pIterator->SetAt(pRange->BeginPos); else pIterator->SetAt(0); CPVT_WordPlace oldplace; while (pIterator->NextWord()) { CPVT_WordPlace place = pIterator->GetAt(); if (pRange && place.WordCmp(pRange->EndPos) > 0) break; CPVT_Word word; if (pIterator->GetWord(word)) { word.WordProps.fFontSize = word.fFontSize; crCurText = ArgbEncode(255, word.WordProps.dwWordColor); if (wrSelect.IsExist()) { bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && place.WordCmp(wrSelect.EndPos) <= 0; if (bSelect) { crCurText = crWhite; } } if (bSelect) { CPVT_Line line; pIterator->GetLine(line); CFX_PathData pathSelBK; pathSelBK.AppendRect(word.ptWord.x + ptOffset.x, line.ptLine.y + line.fLineDescent + ptOffset.y, word.ptWord.x + word.fWidth + ptOffset.x, line.ptLine.y + line.fLineAscent + ptOffset.y); pDevice->DrawPath(&pathSelBK, pUser2Device, NULL, crSelBK, 0, FXFILL_WINDING); } if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || word.WordProps.nHorzScale != 100 || FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 || crOld != crCurText) { if (sTextBuf.GetLength() > 0) { DrawTextString( pDevice, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, sTextBuf.GetByteString(), crOld, 0, wp.nHorzScale); sTextBuf.Clear(); } wp = word.WordProps; ptBT = word.ptWord; crOld = crCurText; } sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, word.Word, 0); if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) { CFX_PathData pathUnderline; CPDF_Rect rcUnderline = GetUnderLineRect(word); pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, rcUnderline.right, rcUnderline.top); pDevice->DrawPath(&pathUnderline, pUser2Device, NULL, crCurText, 0, FXFILL_WINDING); } if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { CFX_PathData pathCrossout; CPDF_Rect rcCrossout = GetCrossoutRect(word); pathCrossout.AppendRect(rcCrossout.left, rcCrossout.bottom, rcCrossout.right, rcCrossout.top); pDevice->DrawPath(&pathCrossout, pUser2Device, NULL, crCurText, 0, FXFILL_WINDING); } oldplace = place; } } if (sTextBuf.GetLength() > 0) { DrawTextString( pDevice, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, sTextBuf.GetByteString(), crOld, 0, wp.nHorzScale); } } } pDevice->RestoreState(); }
void IFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit, FX_COLORREF crTextFill, FX_COLORREF crTextStroke, const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, IFX_SystemHandler* pSystemHandler, void* pFFLData) { FX_BOOL bContinuous = pEdit->GetCharArray() == 0; if (pEdit->GetCharSpace() > 0.0f) bContinuous = FALSE; FX_WORD SubWord = pEdit->GetPasswordChar(); FX_FLOAT fFontSize = pEdit->GetFontSize(); CPVT_WordRange wrSelect = pEdit->GetSelectWordRange(); int32_t nHorzScale = pEdit->GetHorzScale(); FX_COLORREF crCurFill = crTextFill; FX_COLORREF crOldFill = crCurFill; FX_BOOL bSelect = FALSE; const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255); const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113); CFX_ByteTextBuf sTextBuf; int32_t nFontIndex = -1; CPDF_Point ptBT(0.0f, 0.0f); pDevice->SaveState(); if (!rcClip.IsEmpty()) { CPDF_Rect rcTemp = rcClip; pUser2Device->TransformRect(rcTemp); FX_RECT rcDevClip; rcDevClip.left = (int32_t)rcTemp.left; rcDevClip.right = (int32_t)rcTemp.right; rcDevClip.top = (int32_t)rcTemp.top; rcDevClip.bottom = (int32_t)rcTemp.bottom; pDevice->SetClip_Rect(&rcDevClip); } if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap()) { if (pRange) pIterator->SetAt(pRange->BeginPos); else pIterator->SetAt(0); CPVT_WordPlace oldplace; while (pIterator->NextWord()) { CPVT_WordPlace place = pIterator->GetAt(); if (pRange && place.WordCmp(pRange->EndPos) > 0) break; if (wrSelect.IsExist()) { bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && place.WordCmp(wrSelect.EndPos) <= 0; if (bSelect) { crCurFill = crWhite; } else { crCurFill = crTextFill; } } if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) { crCurFill = crTextFill; crOldFill = crCurFill; } CPVT_Word word; if (pIterator->GetWord(word)) { if (bSelect) { CPVT_Line line; pIterator->GetLine(line); if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) { CPDF_Rect rc(word.ptWord.x, line.ptLine.y + line.fLineDescent, word.ptWord.x + word.fWidth, line.ptLine.y + line.fLineAscent); rc.Intersect(rcClip); // CFX_Edit* pEt = (CFX_Edit*)pEdit; // CPDF_Rect rcEdit = pEt->VTToEdit(rc); pSystemHandler->OutputSelectedRect(pFFLData, rc); } else { CFX_PathData pathSelBK; pathSelBK.AppendRect(word.ptWord.x, line.ptLine.y + line.fLineDescent, word.ptWord.x + word.fWidth, line.ptLine.y + line.fLineAscent); pDevice->DrawPath(&pathSelBK, pUser2Device, NULL, crSelBK, 0, FXFILL_WINDING); } } if (bContinuous) { if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex || crOldFill != crCurFill) { if (sTextBuf.GetLength() > 0) { DrawTextString(pDevice, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, sTextBuf.GetByteString(), crOldFill, crTextStroke, nHorzScale); sTextBuf.Clear(); } nFontIndex = word.nFontIndex; ptBT = word.ptWord; crOldFill = crCurFill; } sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord); } else { DrawTextString( pDevice, CPDF_Point(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y), pFontMap->GetPDFFont(word.nFontIndex), fFontSize, pUser2Device, GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord), crCurFill, crTextStroke, nHorzScale); } oldplace = place; } } if (sTextBuf.GetLength() > 0) { DrawTextString( pDevice, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, sTextBuf.GetByteString(), crOldFill, crTextStroke, nHorzScale); } } } pDevice->RestoreState(); }
void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache, CFX_Font* pFont, const FXTEXT_CHARPOS& charpos, int& ps_fontnum, int &ps_glyphindex) { for (int i = 0; i < (int)m_PSFontList.GetSize(); i ++) { CPSFont* pPSFont = m_PSFontList[i]; for (int j = 0; j < pPSFont->m_nGlyphs; j ++) if (pPSFont->m_Glyphs[j].m_pFont == pFont && pPSFont->m_Glyphs[j].m_GlyphIndex == charpos.m_GlyphIndex) { if ((!pPSFont->m_Glyphs[j].m_bGlyphAdjust && !charpos.m_bGlyphAdjust) || (pPSFont->m_Glyphs[j].m_bGlyphAdjust && charpos.m_bGlyphAdjust && (FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[0] - charpos.m_AdjustMatrix[0]) < 0.01 && FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[1] - charpos.m_AdjustMatrix[1]) < 0.01 && FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[2] - charpos.m_AdjustMatrix[2]) < 0.01 && FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[3] - charpos.m_AdjustMatrix[3]) < 0.01))) { ps_fontnum = i; ps_glyphindex = j; return; } } } if (m_PSFontList.GetSize() == 0 || m_PSFontList[m_PSFontList.GetSize() - 1]->m_nGlyphs == 256) { CPSFont* pPSFont = new CPSFont; pPSFont->m_nGlyphs = 0; m_PSFontList.Add(pPSFont); CFX_ByteTextBuf buf; buf << FX_BSTRC("8 dict begin/FontType 3 def/FontMatrix[1 0 0 1 0 0]def\n" "/FontBBox[0 0 0 0]def/Encoding 256 array def 0 1 255{Encoding exch/.notdef put}for\n" "/CharProcs 1 dict def CharProcs begin/.notdef {} def end\n" "/BuildGlyph{1 0 -10 -10 10 10 setcachedevice exch/CharProcs get exch 2 copy known not{pop/.notdef}if get exec}bind def\n" "/BuildChar{1 index/Encoding get exch get 1 index/BuildGlyph get exec}bind def\n" "currentdict end\n"); buf << FX_BSTRC("/X") << m_PSFontList.GetSize() - 1 << FX_BSTRC(" exch definefont pop\n"); m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); buf.Clear(); } ps_fontnum = m_PSFontList.GetSize() - 1; CPSFont* pPSFont = m_PSFontList[ps_fontnum]; ps_glyphindex = pPSFont->m_nGlyphs; pPSFont->m_Glyphs[ps_glyphindex].m_GlyphIndex = charpos.m_GlyphIndex; pPSFont->m_Glyphs[ps_glyphindex].m_pFont = pFont; pPSFont->m_Glyphs[ps_glyphindex].m_bGlyphAdjust = charpos.m_bGlyphAdjust; if (charpos.m_bGlyphAdjust) { pPSFont->m_Glyphs[ps_glyphindex].m_AdjustMatrix[0] = charpos.m_AdjustMatrix[0]; pPSFont->m_Glyphs[ps_glyphindex].m_AdjustMatrix[1] = charpos.m_AdjustMatrix[1]; pPSFont->m_Glyphs[ps_glyphindex].m_AdjustMatrix[2] = charpos.m_AdjustMatrix[2]; pPSFont->m_Glyphs[ps_glyphindex].m_AdjustMatrix[3] = charpos.m_AdjustMatrix[3]; } pPSFont->m_nGlyphs ++; CFX_AffineMatrix matrix; if (charpos.m_bGlyphAdjust) matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); matrix.Concat(1.0f, 0, 0, 1.0f, 0, 0); const CFX_PathData* pPathData = pFaceCache->LoadGlyphPath(pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); if (pPathData == NULL) { return; } CFX_PathData TransformedPath(*pPathData); if (charpos.m_bGlyphAdjust) { TransformedPath.Transform(&matrix); } CFX_ByteTextBuf buf; buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff/CharProcs get begin/") << ps_glyphindex << FX_BSTRC("{"); buf << FX_BSTRC("n "); for (int p = 0; p < TransformedPath.GetPointCount(); p ++) { FX_FLOAT x = TransformedPath.GetPointX(p), y = TransformedPath.GetPointY(p); switch (TransformedPath.GetFlag(p) & FXPT_TYPE) { case FXPT_MOVETO: { buf << x << FX_BSTRC(" ") << y << FX_BSTRC(" m\n"); break; } case FXPT_LINETO: { buf << x << FX_BSTRC(" ") << y << FX_BSTRC(" l\n"); break; } case FXPT_BEZIERTO: { buf << x << FX_BSTRC(" ") << y << FX_BSTRC(" ") << TransformedPath.GetPointX(p + 1) << FX_BSTRC(" ") << TransformedPath.GetPointY(p + 1) << FX_BSTRC(" ") << TransformedPath.GetPointX(p + 2) << FX_BSTRC(" ") << TransformedPath.GetPointY(p + 2) << FX_BSTRC(" c\n"); p += 2; break; } } } buf << FX_BSTRC("f"); buf << FX_BSTRC("}bind def end\n"); buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff/Encoding get ") << ps_glyphindex << FX_BSTRC("/") << ps_glyphindex << FX_BSTRC(" put\n"); m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); }