Example #1
0
void TextRenderer::DoLayout()
{
    const Point new_sz = CalcTextPlc().Size();

    TextObj& t_obj = GetTextObj();
    panLay->update_from_cairo_context(caiCont);
    panLay->set_text(t_obj.Text().c_str());

    const Editor::TextStyle& ts = t_obj.Style();
    Pango::AttrList attr_list;
    if( ts.isUnderlined )
    {
        Pango::AttrInt attr = Pango::Attribute::create_attr_underline(Pango::UNDERLINE_SINGLE);
        attr.set_start_index(0);
        attr.set_end_index(G_MAXUINT);

        attr_list.insert(attr);
    }
    panLay->set_attributes(attr_list);
    Pango::FontDescription dsc(ts.fntDsc);

    Point abs_sz = t_obj.Placement().Size();
    double t_wdh, t_hgt;
    if( abs_sz.x != 0 )
    {
        // размер рассчитываем по ширине, так как она уязвимей к скалированию
        CalcTextSize(dsc, (double)new_sz.x/abs_sz.x, t_wdh, t_hgt);

        //CalcTextSize(dsc, (double)new_sz.x/t_wdh, t_wdh, t_hgt);

        // погрешность - на практике оказалось, что лучше вообще не использовать
        // скалирование по горизонтали перед отображением, потому что отрисовка
        // текста реально может отличаться (по размеру) от того, что говорит
        // Pango::Layout::get_size() (!)
        txtRat.first  = (double)new_sz.x/t_wdh;
    }
    else
    {
        // пусто
        ASSERT( abs_sz.y != 0 ); // размер шрифта ненулевой

        CalcTextSize(dsc, (double)new_sz.y/abs_sz.y, t_wdh, t_hgt);

        txtRat.first  = 1.0;
        //txtSht = 0;
    }
    txtRat.second = (double)new_sz.y/t_hgt;
    txtSht = int( (new_sz.x - t_wdh)/2 );
}
Example #2
0
FWL_ERR CFWL_ToolTipImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
  if (bAutoSize) {
    rect.Set(0, 0, 0, 0);
    if (m_pProperties->m_pThemeProvider == NULL) {
      m_pProperties->m_pThemeProvider = GetAvailableTheme();
    }
    CFX_WideString wsCaption;
    IFWL_ToolTipDP* pData =
        static_cast<IFWL_ToolTipDP*>(m_pProperties->m_pDataProvider);
    if (pData) {
      pData->GetCaption(m_pInterface, wsCaption);
    }
    int32_t iLen = wsCaption.GetLength();
    if (iLen > 0) {
      CFX_SizeF sz = CalcTextSize(wsCaption, m_pProperties->m_pThemeProvider);
      rect.Set(0, 0, sz.x, sz.y);
      rect.width += FWL_WGTCAPACITY_CXBorder * 25;
      rect.height += FWL_WGTCAPACITY_CYBorder * 8;
    }
    CFWL_WidgetImp::GetWidgetRect(rect, TRUE);
  } else {
    rect = m_pProperties->m_rtWidget;
  }
  return FWL_ERR_Succeeded;
}
FWL_ERR CFWL_CheckBoxImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
  if (bAutoSize) {
    rect.Set(0, 0, 0, 0);
    if (!m_pProperties->m_pThemeProvider)
      m_pProperties->m_pThemeProvider = GetAvailableTheme();
    if (!m_pProperties->m_pThemeProvider)
      return FWL_ERR_Indefinite;
    if (!m_pProperties->m_pDataProvider)
      return FWL_ERR_Indefinite;
    CFX_WideString wsCaption;
    m_pProperties->m_pDataProvider->GetCaption(m_pInterface, wsCaption);
    if (wsCaption.GetLength() > 0) {
      CFX_SizeF sz = CalcTextSize(
          wsCaption, m_pProperties->m_pThemeProvider,
          m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine);
      rect.Set(0, 0, sz.x, sz.y);
    }
    rect.Inflate(FWL_CKB_CaptionMargin, FWL_CKB_CaptionMargin);
    IFWL_CheckBoxDP* pData =
        static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider);
    FX_FLOAT fCheckBox = pData->GetBoxSize(m_pInterface);
    rect.width += fCheckBox;
    if (rect.height < fCheckBox) {
      rect.height = fCheckBox;
    }
    CFWL_WidgetImp::GetWidgetRect(rect, TRUE);
  } else {
    rect = m_pProperties->m_rtWidget;
  }
  return FWL_ERR_Succeeded;
}
Example #4
0
  void Text::AddText(const std::wstring& text,
                     unsigned long style,
                     OS::Font *font)
  {
    size_t start,pos;

    if (font==NULL) {
      font=defaultFont;
    }

    start=0;
    pos=0;
    while (pos<text.length()) {
      if (text[pos]==L'\n') {
        AddTextToPart(text.substr(start,pos-start),style,font);
        CloseLine();
        start=pos+1;
      }
      pos++;
    }
    if (start<text.length()) {
      AddTextToPart(text.substr(start,pos-start),style,font);
    }

    if (calced) {
      CalcTextSize();

      if (visible) {
        Redraw();
      }
    }
  }
Example #5
0
FWL_ERR CFWL_PushButtonImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
  if (bAutoSize) {
    rect.Set(0, 0, 0, 0);
    if (m_pProperties->m_pThemeProvider == NULL) {
      m_pProperties->m_pThemeProvider = GetAvailableTheme();
    }
    CFX_WideString wsCaption;
    IFWL_PushButtonDP* pData =
        static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider);
    if (pData) {
      pData->GetCaption(m_pInterface, wsCaption);
    }
    int32_t iLen = wsCaption.GetLength();
    if (iLen > 0) {
      CFX_SizeF sz = CalcTextSize(wsCaption, m_pProperties->m_pThemeProvider);
      rect.Set(0, 0, sz.x, sz.y);
    }
    FX_FLOAT* fcaption =
        static_cast<FX_FLOAT*>(GetThemeCapacity(FWL_WGTCAPACITY_PSB_Margin));
    rect.Inflate(*fcaption, *fcaption);
    CFWL_WidgetImp::GetWidgetRect(rect, TRUE);
  } else {
    rect = m_pProperties->m_rtWidget;
  }
  return FWL_ERR_Succeeded;
}
Example #6
0
void
Canvas::DrawClippedText(int x, int y, unsigned width,
                        const TCHAR *text)
{
  const PixelSize size = CalcTextSize(text);

  PixelRect rc;
  ::SetRect(&rc, x, y, x + std::min(width, unsigned(size.cx)), y + size.cy);
  DrawClippedText(x, y, rc, text);
}
Example #7
0
void
Canvas::text_clipped(PixelScalar x, PixelScalar y, UPixelScalar width,
                     const TCHAR *text)
{
  const PixelSize size = CalcTextSize(text);

  PixelRect rc;
  ::SetRect(&rc, x, y, x + min(width, (UPixelScalar)size.cx), y + size.cy);
  text_clipped(x, y, rc, text);
}
Example #8
0
void
Canvas::DrawClippedText(int x, int y, unsigned width,
                        const TCHAR *text)
{
  const PixelSize size = CalcTextSize(text);

  RECT rc;
  ::SetRect(&rc, x, y, x + std::min(width, unsigned(size.cx)), y + size.cy);
  ::ExtTextOut(dc, x, y, ETO_CLIPPED, &rc, text, _tcslen(text), nullptr);
}
Example #9
0
void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr,
                                 int32_t iLength,
                                 CFX_RectF& rect) {
  if (!pwsStr || iLength < 1) {
    rect.width = 0.0f;
    rect.height = 0.0f;
  } else {
    CalcTextSize(pwsStr, iLength, rect);
  }
}
Example #10
0
void HookSvc::ProcessBigLabel(RefPtr<Pango::Layout> lay, const Point& pos)
{
    DPoint user_pos(CR::DeviceToUser(cont, PhisPos()));
    DPoint sz(CalcTextSize(lay));

    DRect user_rct(RectASz(DPoint(pos), sz));
    if( user_rct.Contains(user_pos) )
    {
        pAction->AtBigLabel();
    }
}
Example #11
0
void Service::FormBigLabel()
{
    RefPtr<Pango::Layout> lay = Pango::Layout::create(cont);
    //std::string mark_str = "<span font_desc=\"FreeSans Bold 11\" color=\"darkblue\" underline=\"single\">" +
    std::string mark_str = "<span font_desc=\"Nimbus Sans L Bold Condensed 13\" color=\"#" +
        ColorToString(BLUE_CLR) + "\" underline=\"single\">" + CurPointerStr(trkLay) + "</span>";
    lay->set_markup(mark_str);

    int sh = (int)(HEADER_WDH - CalcTextSize(lay).x) / 2; // 0;
    ProcessBigLabel(lay, Point(sh, 8));
}
Example #12
0
const PixelSize
Canvas::CalcTextSize(const TCHAR *text, size_t length) const
{
  TCHAR *duplicated = _tcsdup(text);
  duplicated[length] = 0;

  const PixelSize size = CalcTextSize(duplicated);
  free(duplicated);

  return size;
}
Example #13
0
  void Text::CalcSize()
  {
    CalcTextSize();

    calced=true;
    width=textWidth;
    height=textHeight;
    minWidth=textWidth;
    minHeight=textHeight;

    Object::CalcSize();
  }
Example #14
0
/**
 * Ok return our dimensions
 */
nsSize
nsTextBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState)
{
    CalcTextSize(aBoxLayoutState);

    nsSize size = mTextSize;
    DISPLAY_PREF_SIZE(this, size);

    AddBorderAndPadding(size);
    nsIBox::AddCSSPrefSize(aBoxLayoutState, this, size);

    return size;
}
Example #15
0
nscoord
nsTextBoxFrame::GetBoxAscent(nsBoxLayoutState& aBoxLayoutState)
{
    CalcTextSize(aBoxLayoutState);

    nscoord ascent = mAscent;

    nsMargin m(0,0,0,0);
    GetBorderAndPadding(m);
    ascent += m.top;

    return ascent;
}
Example #16
0
void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr,
                            int32_t iLength,
                            CFX_RectF& rect) {
  if (!pwsStr || iLength < 1) {
    rect.width = 0.0f;
    rect.height = 0.0f;
  } else {
    CFX_Matrix rm;
    rm.SetReverse(m_Matrix);
    rm.TransformRect(rect);
    CalcTextSize(pwsStr, iLength, rect);
    m_Matrix.TransformRect(rect);
  }
}
Example #17
0
void Service::FormTrackName()
{
    Rect v_rct(GetTrackLocation(false));
    const std::string& name = CurrVideo->mdName;
    if( !name.empty() )
    {
        RefPtr<Pango::Layout> lay = Pango::Layout::create(cont);
        Pango::FontDescription dsc("Sans Italic 12");
        lay->set_font_description(dsc);
        lay->set_text(name);

        Rect txt_rct( CeilRect(RectASz(DPoint(3 - shift.x, 3), CalcTextSize(lay))) );
        if( v_rct.Intersects(txt_rct) )
            ProcessTrackName(lay, txt_rct);
    }
}
Example #18
0
const PixelSize
Canvas::CalcTextSize(const TCHAR *text, size_t length) const
{
  assert(text != nullptr);

  TCHAR *duplicated = _tcsdup(text);
  duplicated[length] = 0;

#ifndef UNICODE
  assert(ValidateUTF8(duplicated));
#endif

  const PixelSize size = CalcTextSize(duplicated);
  free(duplicated);

  return size;
}
Example #19
0
/**
 * Ok return our dimensions
 */
nsSize
nsTextBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
{
    CalcTextSize(aBoxLayoutState);

    nsSize size = mTextSize;
    DISPLAY_MIN_SIZE(this, size);

    // if there is cropping our min width becomes our border and padding
    if (mCropType != CropNone)
        size.width = 0;

    AddBorderAndPadding(size);
    nsIBox::AddCSSMinSize(aBoxLayoutState, this, size);

    return size;
}
Example #20
0
LRESULT OMenu::onMeasureItem(HWND /*hWnd*/, UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
	bHandled = FALSE;
	if (wParam == NULL) {
		MEASUREITEMSTRUCT* mis = (MEASUREITEMSTRUCT*)lParam;
		if (mis->CtlType == ODT_MENU) {
			OMenuItem* mi = (OMenuItem*)mis->itemData;
			if (mi) {
				bHandled = TRUE;
				tstring& text = mi->text;

				SIZE size;
				CalcTextSize(text, WinUtil::boldFont, &size);
				mis->itemWidth = size.cx + 4;
				mis->itemHeight = size.cy + 4;

				return TRUE;
			}
		}
	}
	return S_OK;
}
Example #21
0
const PixelSize
Canvas::CalcTextSize(const TCHAR *text) const
{
  return CalcTextSize(text, _tcslen(text));
}
Example #22
0
bool ImGui::InputTextM(const char* label, std::string& text)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)	
	bool ret = InputTextEx(label, &text[0], text.capacity(), ImVec2(0, 0), 0, 0, nullptr);
	return ret;
#else
	ImGuiWindow* window = GetCurrentWindow();
	if (window->SkipItems)
		return false;

	ImGuiContext& g = *GImGui;
	const ImGuiIO& io = g.IO;
	const ImGuiStyle& style = g.Style;
	//============================================
	const ImGuiID id = window->GetID(label);
	const ImVec2 label_size = CalcTextSize(label, NULL, true);
	ImVec2 size = CalcItemSize(ImVec2(0, 0), CalcItemWidth(), label_size.y + style.FramePadding.y*2.0f);
	const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
	const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
	//============================================
	ItemSize(total_bb, style.FramePadding.y);
	if (!ItemAdd(total_bb, &id))
		return false;

	const bool hovered = IsHovered(frame_bb, id);
	if (hovered)
	{
		SetHoveredID(id);
		g.MouseCursor = ImGuiMouseCursor_TextInput;
	}
	ImGuiTextEditState& edit_state = g.InputTextState;
	const bool user_clicked = hovered && io.MouseClicked[0];
	if (user_clicked)
	{
		if (g.ActiveId != id)
		{
			edit_state.CursorAnimReset();
		}
		SetActiveID(id, window);
		FocusWindow(window);
	}
	else if (io.MouseClicked[0])
	{
		// Release focus when we click outside
		if (g.ActiveId == id)
			SetActiveID(0, NULL);
	}

	if (g.ActiveId == id)
	{
		//window->DrawList->AddRectFilled(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_TextSelectedBg), style.FrameRounding);
		RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_TextSelectedBg), true, style.FrameRounding);
		ImRect frame_select(frame_bb);
		frame_select.Reduce(ImVec2(2, 2));
		RenderFrame(frame_select.Min, frame_select.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
	}else
	{
		RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
	}

	//============================================
	int w = snprintf(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%s", text.c_str());
	int tempSize = IM_ARRAYSIZE(g.TempBuffer);
	g.TempBuffer[tempSize - 1] = 0;
	const char* text_end = g.TempBuffer + ((w == -1) ? tempSize : w);

	// Render Text
	const ImVec4 clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x, frame_bb.Min.y + size.y); // Not using frame_bb.Max because we have adjusted size
	ImVec2 render_pos = frame_bb.Min + style.FramePadding;
	window->DrawList->AddText(g.Font, g.FontSize, render_pos, GetColorU32(ImGuiCol_Text), g.TempBuffer, text_end, 0.0f, &clip_rect);

	if (label_size.x > 0)
		RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);

	return user_clicked;
#endif
}
Example #23
0
 gcc_pure
 unsigned CalcTextWidth(const TCHAR *text) const {
   return CalcTextSize(text).cx;
 }
Example #24
0
void
Canvas::formatted_text(PixelRect *rc, const TCHAR *text, unsigned format) {
  if (font == NULL)
    return;

  UPixelScalar skip = font->GetLineSpacing();
  unsigned max_lines = (format & DT_CALCRECT) ? -1 :
                       (rc->bottom - rc->top + skip - 1) / skip;

  size_t len = _tcslen(text);
  TCHAR *duplicated = new TCHAR[len + 1], *p = duplicated;
  unsigned lines = 1;
  for (const TCHAR *i = text; *i != _T('\0'); ++i) {
    TCHAR ch = *i;
    if (ch == _T('\n')) {
      /* explicit line break */

      if (++lines >= max_lines)
        break;

      ch = _T('\0');
    } else if (ch == _T('\r'))
      /* skip */
      continue;
    else if ((unsigned)ch < 0x20)
      /* replace non-printable characters */
      ch = _T(' ');

    *p++ = ch;
  }

  *p = _T('\0');
  len = p - duplicated;

  // simple wordbreak algorithm. looks for single spaces only, no tabs,
  // no grouping of multiple spaces
  if (format & DT_WORDBREAK) {
    for (size_t i = 0; i < len; i += _tcslen(duplicated + i) + 1) {
      PixelSize sz = CalcTextSize(duplicated + i);
      TCHAR *prev_p = NULL;

      // remove words from behind till line fits or no more space is found
      while (sz.cx > rc->right - rc->left &&
             (p = _tcsrchr(duplicated + i, _T(' '))) != NULL) {
        if (prev_p)
          *prev_p = _T(' ');
        *p = _T('\0');
        prev_p = p;
        sz = CalcTextSize(duplicated + i);
      }

      if (prev_p) {
        lines++;
        if (lines >= max_lines)
          break;
      }
    }
  }

  if (format & DT_CALCRECT) {
    rc->bottom = rc->top + lines * skip;
    delete[] duplicated;
    return;
  }

  PixelScalar y = (format & DT_VCENTER) && lines < max_lines
    ? (PixelScalar)(rc->top + rc->bottom - lines * skip) / 2
    : rc->top;
  for (size_t i = 0; i < len; i += _tcslen(duplicated + i) + 1) {
    if (duplicated[i] != _T('\0')) {
      PixelScalar x;
      if (format & (DT_RIGHT | DT_CENTER)) {
        PixelSize sz = CalcTextSize(duplicated + i);
        x = (format & DT_CENTER) ? (rc->left + rc->right - sz.cx)/2 :
                                    rc->right - sz.cx;  // DT_RIGHT
      } else {  // default is DT_LEFT
        x = rc->left;
      }

      TextAutoClipped(x, y, duplicated + i);
    }
    y += skip;
    if (y >= rc->bottom)
      break;
  }

  delete[] duplicated;
}
Example #25
0
void PointerCoverSvc::ProcessBigLabel(RefPtr<Pango::Layout> lay, const Point& pos)
{
    DPoint sz(CalcTextSize(lay));
    AddRect( RectASz(DPoint(pos), sz) );
}
Example #26
0
unsigned
Canvas::DrawFormattedText(const PixelRect r, const TCHAR *text,
                          unsigned format)
{
  assert(text != nullptr);
#ifndef UNICODE
  assert(ValidateUTF8(text));
#endif

  if (font == nullptr)
    return 0;

  unsigned skip = font->GetLineSpacing();
  unsigned max_lines = (format & DT_CALCRECT) ? -1 :
    (r.GetHeight() + skip - 1) / skip;

  size_t len = _tcslen(text);
  TCHAR *duplicated = new TCHAR[len + 1], *p = duplicated;
  unsigned lines = 1;
  for (const TCHAR *i = text; *i != _T('\0'); ++i) {
    TCHAR ch = *i;
    if (ch == _T('\n')) {
      /* explicit line break */

      if (++lines > max_lines)
        break;

      ch = _T('\0');
    } else if (ch == _T('\r'))
      /* skip */
      continue;
    else if ((unsigned)ch < 0x20)
      /* replace non-printable characters */
      ch = _T(' ');

    *p++ = ch;
  }

  *p = _T('\0');
  len = p - duplicated;

  // simple wordbreak algorithm. looks for single spaces only, no tabs,
  // no grouping of multiple spaces
  for (size_t i = 0; i < len; i += _tcslen(duplicated + i) + 1) {
    PixelSize sz = CalcTextSize(duplicated + i);
    TCHAR *prev_p = nullptr;

    // remove words from behind till line fits or no more space is found
    while (unsigned(sz.cx) > r.GetWidth() &&
           (p = StringFindLast(duplicated + i, _T(' '))) != nullptr) {
      if (prev_p)
        *prev_p = _T(' ');
      *p = _T('\0');
      prev_p = p;
      sz = CalcTextSize(duplicated + i);
    }

    if (prev_p) {
      lines++;
      if (lines >= max_lines)
        break;
    }
  }

  if (format & DT_CALCRECT) {
    delete[] duplicated;
    return lines * skip;
  }

  int y = (format & DT_VCENTER) && lines < max_lines
    ? (r.top + r.bottom - lines * skip) / 2
    : r.top;
  for (size_t i = 0; i < len; i += _tcslen(duplicated + i) + 1) {
    if (duplicated[i] != _T('\0')) {
      int x;
      if (format & (DT_RIGHT | DT_CENTER)) {
        PixelSize sz = CalcTextSize(duplicated + i);
        x = (format & DT_CENTER)
          ? (r.left + r.right - sz.cx) / 2
          : r.right - sz.cx;  // DT_RIGHT
      } else {  // default is DT_LEFT
        x = r.left;
      }

      TextAutoClipped(x, y, duplicated + i);

      if (format & DT_UNDERLINE)
        DrawHLine(x, x + CalcTextWidth(duplicated + i),
                  y + font->GetAscentHeight() + 1, text_color);
    }
    y += skip;
    if (y >= r.bottom)
      break;
  }

  delete[] duplicated;
  return lines * skip;
}
Example #27
0
 gcc_pure
 UPixelScalar CalcTextWidth(const TCHAR *text) const {
   return CalcTextSize(text).cx;
 }