summaryrefslogtreecommitdiff
path: root/fpdfsdk/pwl/cpwl_edit_impl.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-08-15 13:56:43 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 21:33:32 +0000
commiteb14e04c79c575146fe96c025dbf56b7440870c7 (patch)
tree323ca30b3b5b2df46427e336c3482901ca26db8f /fpdfsdk/pwl/cpwl_edit_impl.cpp
parent6e524ad89eac22f0e5d5475652ec78c609b788e8 (diff)
downloadpdfium-eb14e04c79c575146fe96c025dbf56b7440870c7.tar.xz
Change a bunch of methods to take a const CFX_Matrix& param.chromium/3187
Simplify some code along the way. Change-Id: I0022c8a82188192c63b9ac0bc87e9b9dbf983040 Reviewed-on: https://pdfium-review.googlesource.com/10852 Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/pwl/cpwl_edit_impl.cpp')
-rw-r--r--fpdfsdk/pwl/cpwl_edit_impl.cpp189
1 files changed, 92 insertions, 97 deletions
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp
index 808eddb7cb..f26811e137 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp
@@ -41,33 +41,27 @@ void DrawTextString(CFX_RenderDevice* pDevice,
const CFX_PointF& pt,
CPDF_Font* pFont,
float fFontSize,
- CFX_Matrix* pUser2Device,
+ const CFX_Matrix& mtUser2Device,
const CFX_ByteString& str,
FX_ARGB crTextFill,
int32_t nHorzScale) {
- CFX_PointF pos = pUser2Device->Transform(pt);
-
- if (pFont) {
- if (nHorzScale != 100) {
- CFX_Matrix mt(nHorzScale / 100.0f, 0, 0, 1, 0, 0);
- mt.Concat(*pUser2Device);
-
- CPDF_RenderOptions ro;
- ro.m_Flags = RENDER_CLEARTYPE;
- ro.m_ColorMode = CPDF_RenderOptions::kNormal;
-
- CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize,
- &mt, str, crTextFill, nullptr, &ro);
- } else {
- CPDF_RenderOptions ro;
- ro.m_Flags = RENDER_CLEARTYPE;
- ro.m_ColorMode = CPDF_RenderOptions::kNormal;
+ if (!pFont)
+ return;
- CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize,
- pUser2Device, str, crTextFill, nullptr,
- &ro);
- }
+ CFX_PointF pos = mtUser2Device.Transform(pt);
+ CFX_Matrix mt;
+ if (nHorzScale == 100) {
+ mt = mtUser2Device;
+ } else {
+ mt = CFX_Matrix(nHorzScale / 100.0f, 0, 0, 1, 0, 0);
+ mt.Concat(mtUser2Device);
}
+
+ CPDF_RenderOptions ro;
+ ro.m_Flags = RENDER_CLEARTYPE;
+ ro.m_ColorMode = CPDF_RenderOptions::kNormal;
+ CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize,
+ &mt, str, crTextFill, nullptr, &ro);
}
} // namespace
@@ -448,7 +442,7 @@ void CFXEU_InsertText::Undo() {
// static
void CPWL_EditImpl::DrawEdit(CFX_RenderDevice* pDevice,
- CFX_Matrix* pUser2Device,
+ const CFX_Matrix& mtUser2Device,
CPWL_EditImpl* pEdit,
FX_COLORREF crTextFill,
const CFX_FloatRect& rcClip,
@@ -467,8 +461,8 @@ void CPWL_EditImpl::DrawEdit(CFX_RenderDevice* pDevice,
FX_COLORREF crOldFill = crCurFill;
bool bSelect = false;
- const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255);
- const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113);
+ static const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255);
+ static const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113);
std::ostringstream sTextBuf;
int32_t nFontIndex = -1;
@@ -476,91 +470,92 @@ void CPWL_EditImpl::DrawEdit(CFX_RenderDevice* pDevice,
CFX_RenderDevice::StateRestorer restorer(pDevice);
if (!rcClip.IsEmpty()) {
CFX_FloatRect rcTemp = rcClip;
- pUser2Device->TransformRect(rcTemp);
+ mtUser2Device.TransformRect(rcTemp);
pDevice->SetClip_Rect(rcTemp.ToFxRect());
}
CPWL_EditImpl_Iterator* pIterator = pEdit->GetIterator();
- if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
+ IPVT_FontMap* pFontMap = pEdit->GetFontMap();
+ if (!pFontMap)
+ return;
- CPVT_WordPlace oldplace;
- while (pIterator->NextWord()) {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place > pRange->EndPos)
- break;
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
- if (!wrSelect.IsEmpty()) {
- bSelect = place > wrSelect.BeginPos && place <= wrSelect.EndPos;
- crCurFill = bSelect ? crWhite : 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()) {
- CFX_FloatRect rc(word.ptWord.x, line.ptLine.y + line.fLineDescent,
- word.ptWord.x + word.fWidth,
- line.ptLine.y + line.fLineAscent);
- rc.Intersect(rcClip);
- 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, nullptr, crSelBK, 0,
- FXFILL_WINDING);
- }
+ CPVT_WordPlace oldplace;
+ while (pIterator->NextWord()) {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place > pRange->EndPos)
+ break;
+
+ if (!wrSelect.IsEmpty()) {
+ bSelect = place > wrSelect.BeginPos && place <= wrSelect.EndPos;
+ crCurFill = bSelect ? crWhite : 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()) {
+ CFX_FloatRect rc(word.ptWord.x, line.ptLine.y + line.fLineDescent,
+ word.ptWord.x + word.fWidth,
+ line.ptLine.y + line.fLineAscent);
+ rc.Intersect(rcClip);
+ 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, &mtUser2Device, nullptr, crSelBK, 0,
+ FXFILL_WINDING);
}
+ }
- if (bContinuous) {
- if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex ||
- crOldFill != crCurFill) {
- if (sTextBuf.tellp() > 0) {
- DrawTextString(
- pDevice, CFX_PointF(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y),
- pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device,
- CFX_ByteString(sTextBuf), crOldFill, nHorzScale);
-
- sTextBuf.str("");
- }
- nFontIndex = word.nFontIndex;
- ptBT = word.ptWord;
- crOldFill = crCurFill;
- }
+ if (bContinuous) {
+ if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex ||
+ crOldFill != crCurFill) {
+ if (sTextBuf.tellp() > 0) {
+ DrawTextString(
+ pDevice, CFX_PointF(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y),
+ pFontMap->GetPDFFont(nFontIndex), fFontSize, mtUser2Device,
+ CFX_ByteString(sTextBuf), crOldFill, nHorzScale);
- sTextBuf << pEdit->GetPDFWordString(word.nFontIndex, word.Word,
- SubWord);
- } else {
- DrawTextString(
- pDevice,
- CFX_PointF(word.ptWord.x + ptOffset.x,
- word.ptWord.y + ptOffset.y),
- pFontMap->GetPDFFont(word.nFontIndex), fFontSize, pUser2Device,
- pEdit->GetPDFWordString(word.nFontIndex, word.Word, SubWord),
- crCurFill, nHorzScale);
+ sTextBuf.str("");
+ }
+ nFontIndex = word.nFontIndex;
+ ptBT = word.ptWord;
+ crOldFill = crCurFill;
}
- oldplace = place;
+
+ sTextBuf << pEdit->GetPDFWordString(word.nFontIndex, word.Word,
+ SubWord);
+ } else {
+ DrawTextString(
+ pDevice,
+ CFX_PointF(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y),
+ pFontMap->GetPDFFont(word.nFontIndex), fFontSize, mtUser2Device,
+ pEdit->GetPDFWordString(word.nFontIndex, word.Word, SubWord),
+ crCurFill, nHorzScale);
}
+ oldplace = place;
}
+ }
- if (sTextBuf.tellp() > 0) {
- DrawTextString(pDevice,
- CFX_PointF(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y),
- pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device,
- CFX_ByteString(sTextBuf), crOldFill, nHorzScale);
- }
+ if (sTextBuf.tellp() > 0) {
+ DrawTextString(pDevice,
+ CFX_PointF(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y),
+ pFontMap->GetPDFFont(nFontIndex), fFontSize, mtUser2Device,
+ CFX_ByteString(sTextBuf), crOldFill, nHorzScale);
}
}