예제 #1
0
FX_BOOL CFX_PathData::GetZeroAreaPath(CFX_PathData& NewPath,
                                      CFX_AffineMatrix* pMatrix,
                                      FX_BOOL& bThin,
                                      FX_BOOL bAdjust) const {
  if (m_PointCount < 3) {
    return FALSE;
  }
  if (m_PointCount == 3 && (m_pPoints[0].m_Flag & FXPT_TYPE) == FXPT_MOVETO &&
      (m_pPoints[1].m_Flag & FXPT_TYPE) == FXPT_LINETO &&
      (m_pPoints[2].m_Flag & FXPT_TYPE) == FXPT_LINETO &&
      m_pPoints[0].m_PointX == m_pPoints[2].m_PointX &&
      m_pPoints[0].m_PointY == m_pPoints[2].m_PointY) {
    NewPath.AddPointCount(2);
    if (bAdjust) {
      if (pMatrix) {
        FX_FLOAT x = m_pPoints[0].m_PointX, y = m_pPoints[0].m_PointY;
        pMatrix->TransformPoint(x, y);
        x = (int)x + 0.5f;
        y = (int)y + 0.5f;
        NewPath.SetPoint(0, x, y, FXPT_MOVETO);
        x = m_pPoints[1].m_PointX, y = m_pPoints[1].m_PointY;
        pMatrix->TransformPoint(x, y);
        x = (int)x + 0.5f;
        y = (int)y + 0.5f;
        NewPath.SetPoint(1, x, y, FXPT_LINETO);
        pMatrix->SetIdentity();
      } else {
        FX_FLOAT x = (int)m_pPoints[0].m_PointX + 0.5f,
                 y = (int)m_pPoints[0].m_PointY + 0.5f;
        NewPath.SetPoint(0, x, y, FXPT_MOVETO);
        x = (int)m_pPoints[1].m_PointX + 0.5f,
        y = (int)m_pPoints[1].m_PointY + 0.5f;
        NewPath.SetPoint(1, x, y, FXPT_LINETO);
      }
    } else {
      NewPath.SetPoint(0, m_pPoints[0].m_PointX, m_pPoints[0].m_PointY,
                       FXPT_MOVETO);
      NewPath.SetPoint(1, m_pPoints[1].m_PointX, m_pPoints[1].m_PointY,
                       FXPT_LINETO);
    }
    if (m_pPoints[0].m_PointX != m_pPoints[1].m_PointX &&
        m_pPoints[0].m_PointY != m_pPoints[1].m_PointY) {
      bThin = TRUE;
    }
    return TRUE;
  }
  if (((m_PointCount > 3) && (m_PointCount % 2))) {
    int mid = m_PointCount / 2;
    FX_BOOL bZeroArea = FALSE;
    CFX_PathData t_path;
    for (int i = 0; i < mid; i++) {
      if (!(m_pPoints[mid - i - 1].m_PointX ==
                m_pPoints[mid + i + 1].m_PointX &&
            m_pPoints[mid - i - 1].m_PointY ==
                m_pPoints[mid + i + 1].m_PointY &&
            ((m_pPoints[mid - i - 1].m_Flag & FXPT_TYPE) != FXPT_BEZIERTO &&
             (m_pPoints[mid + i + 1].m_Flag & FXPT_TYPE) != FXPT_BEZIERTO))) {
        bZeroArea = TRUE;
        break;
      }
      int new_count = t_path.GetPointCount();
      t_path.AddPointCount(2);
      t_path.SetPoint(new_count, m_pPoints[mid - i].m_PointX,
                      m_pPoints[mid - i].m_PointY, FXPT_MOVETO);
      t_path.SetPoint(new_count + 1, m_pPoints[mid - i - 1].m_PointX,
                      m_pPoints[mid - i - 1].m_PointY, FXPT_LINETO);
    }
    if (!bZeroArea) {
      NewPath.Append(&t_path, NULL);
      bThin = TRUE;
      return TRUE;
    }
  }
  int stratPoint = 0;
  int next = 0, i;
  for (i = 0; i < m_PointCount; i++) {
    int point_type = m_pPoints[i].m_Flag & FXPT_TYPE;
    if (point_type == FXPT_MOVETO) {
      stratPoint = i;
    } else if (point_type == FXPT_LINETO) {
      next = (i + 1 - stratPoint) % (m_PointCount - stratPoint) + stratPoint;
      if ((m_pPoints[next].m_Flag & FXPT_TYPE) != FXPT_BEZIERTO &&
          (m_pPoints[next].m_Flag & FXPT_TYPE) != FXPT_MOVETO) {
        if ((m_pPoints[i - 1].m_PointX == m_pPoints[i].m_PointX &&
             m_pPoints[i].m_PointX == m_pPoints[next].m_PointX) &&
            ((m_pPoints[i].m_PointY - m_pPoints[i - 1].m_PointY) *
                 (m_pPoints[i].m_PointY - m_pPoints[next].m_PointY) >
             0)) {
          int pre = i;
          if (FXSYS_fabs(m_pPoints[i].m_PointY - m_pPoints[i - 1].m_PointY) <
              FXSYS_fabs(m_pPoints[i].m_PointY - m_pPoints[next].m_PointY)) {
            pre--;
            next--;
          }
          int new_count = NewPath.GetPointCount();
          NewPath.AddPointCount(2);
          NewPath.SetPoint(new_count, m_pPoints[pre].m_PointX,
                           m_pPoints[pre].m_PointY, FXPT_MOVETO);
          NewPath.SetPoint(new_count + 1, m_pPoints[next].m_PointX,
                           m_pPoints[next].m_PointY, FXPT_LINETO);
        } else if ((m_pPoints[i - 1].m_PointY == m_pPoints[i].m_PointY &&
                    m_pPoints[i].m_PointY == m_pPoints[next].m_PointY) &&
                   ((m_pPoints[i].m_PointX - m_pPoints[i - 1].m_PointX) *
                        (m_pPoints[i].m_PointX - m_pPoints[next].m_PointX) >
                    0)) {
          int pre = i;
          if (FXSYS_fabs(m_pPoints[i].m_PointX - m_pPoints[i - 1].m_PointX) <
              FXSYS_fabs(m_pPoints[i].m_PointX - m_pPoints[next].m_PointX)) {
            pre--;
            next--;
          }
          int new_count = NewPath.GetPointCount();
          NewPath.AddPointCount(2);
          NewPath.SetPoint(new_count, m_pPoints[pre].m_PointX,
                           m_pPoints[pre].m_PointY, FXPT_MOVETO);
          NewPath.SetPoint(new_count + 1, m_pPoints[next].m_PointX,
                           m_pPoints[next].m_PointY, FXPT_LINETO);
        } else if ((m_pPoints[i - 1].m_Flag & FXPT_TYPE) == FXPT_MOVETO &&
                   (m_pPoints[next].m_Flag & FXPT_TYPE) == FXPT_LINETO &&
                   m_pPoints[i - 1].m_PointX == m_pPoints[next].m_PointX &&
                   m_pPoints[i - 1].m_PointY == m_pPoints[next].m_PointY &&
                   m_pPoints[next].m_Flag & FXPT_CLOSEFIGURE) {
          int new_count = NewPath.GetPointCount();
          NewPath.AddPointCount(2);
          NewPath.SetPoint(new_count, m_pPoints[i - 1].m_PointX,
                           m_pPoints[i - 1].m_PointY, FXPT_MOVETO);
          NewPath.SetPoint(new_count + 1, m_pPoints[i].m_PointX,
                           m_pPoints[i].m_PointY, FXPT_LINETO);
          bThin = TRUE;
        }
      }
    } else if (point_type == FXPT_BEZIERTO) {
      i += 2;
      continue;
    }
  }
  if (m_PointCount > 3 && NewPath.GetPointCount()) {
    bThin = TRUE;
  }
  if (NewPath.GetPointCount() == 0) {
    return FALSE;
  }
  return TRUE;
}
예제 #2
0
void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
                                   CFX_Matrix* pUser2Device) {
  CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);

  CPDF_Rect rcClient = GetClientRect();
  CFX_ByteTextBuf sLine;

  int32_t nCharArray = m_pEdit->GetCharArray();
  FX_SAFE_INT32 nCharArraySafe = nCharArray;
  nCharArraySafe -= 1;
  nCharArraySafe *= 2;

  if (nCharArray > 0 && nCharArraySafe.IsValid()) {
    switch (GetBorderStyle()) {
      case PBS_SOLID: {
        CFX_GraphStateData gsd;
        gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();

        CFX_PathData path;
        path.SetPointCount(nCharArraySafe.ValueOrDie());

        for (int32_t i = 0; i < nCharArray - 1; i++) {
          path.SetPoint(
              i * 2,
              rcClient.left +
                  ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
              rcClient.bottom, FXPT_MOVETO);
          path.SetPoint(
              i * 2 + 1,
              rcClient.left +
                  ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
              rcClient.top, FXPT_LINETO);
        }
        if (path.GetPointCount() > 0)
          pDevice->DrawPath(
              &path, pUser2Device, &gsd, 0,
              CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
              FXFILL_ALTERNATE);
      } break;
      case PBS_DASH: {
        CFX_GraphStateData gsd;
        gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();

        gsd.SetDashCount(2);
        gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
        gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
        gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;

        CFX_PathData path;
        path.SetPointCount(nCharArraySafe.ValueOrDie());

        for (int32_t i = 0; i < nCharArray - 1; i++) {
          path.SetPoint(
              i * 2,
              rcClient.left +
                  ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
              rcClient.bottom, FXPT_MOVETO);
          path.SetPoint(
              i * 2 + 1,
              rcClient.left +
                  ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
              rcClient.top, FXPT_LINETO);
        }
        if (path.GetPointCount() > 0)
          pDevice->DrawPath(
              &path, pUser2Device, &gsd, 0,
              CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
              FXFILL_ALTERNATE);
      } break;
    }
  }

  CPDF_Rect rcClip;
  CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
  CPVT_WordRange* pRange = NULL;

  if (!HasFlag(PES_TEXTOVERFLOW)) {
    rcClip = GetClientRect();
    pRange = &wrRange;
  }
  IFX_SystemHandler* pSysHandler = GetSystemHandler();
  IFX_Edit::DrawEdit(
      pDevice, pUser2Device, m_pEdit,
      CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
      CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()),
      rcClip, CPDF_Point(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller);

  if (HasFlag(PES_SPELLCHECK)) {
    CPWL_Utils::DrawEditSpellCheck(pDevice, pUser2Device, m_pEdit, rcClip,
                                   CPDF_Point(0.0f, 0.0f), pRange,
                                   GetCreationParam().pSpellCheck);
  }
}