48e08aa973
<ostream> is one of the more expensive headers to include and that's amplified by SkRefCnt.h's popularity. We've been including <ostream> for sk_sp's operator<<. That's only used by Chromium and while we could just sprinkle in a bunch of .get() calls and remove operator<<, when I started going through and actually doing that I got the feeling I was making things pointlessly harder to read and write, and wanted to find a way to make it actually work. My next instinct was to template it without mentioning ostreams, template <typename OS, typename T> auto operator<<(OS& os, const sk_sp<T>& sp) -> decltype(os << sp.get()) { return os << sp.get(); } but that makes this operator<< ambiguous with some other templated operator<< in GTest. They got in first, so they win... So ultimately, switch <ostream> to <iosfwd>. Anyone using our operator<<() presumably has <ostream> included already, and the #include cost for <iosfwd> is small enough that I don't think we'll mind keeping this around indefinitely. To repro, look at before/after of -ftime-trace: ~/chromium/src/third_party/llvm-build/Release+Asserts/bin/clang++ -I. -Os -c src/core/SkCanvas.cpp -ftime-trace I have tested locally that Chromium builds with this change. Change-Id: I9decc2e65b5cc8fd07d8106a5eff81901aedd7d5 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/237190 Commit-Queue: Mike Klein <mtklein@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
104 lines
3.4 KiB
C++
104 lines
3.4 KiB
C++
// Copyright 2019 Google LLC.
|
|
#ifndef ParagraphStyle_DEFINED
|
|
#define ParagraphStyle_DEFINED
|
|
|
|
#include "include/core/SkFontStyle.h"
|
|
#include "modules/skparagraph/include/DartTypes.h"
|
|
#include "modules/skparagraph/include/TextStyle.h"
|
|
#include <string> // std::u16string
|
|
|
|
namespace skia {
|
|
namespace textlayout {
|
|
|
|
struct StrutStyle {
|
|
StrutStyle();
|
|
|
|
const std::vector<SkString>& getFontFamilies() const { return fFontFamilies; }
|
|
void setFontFamilies(std::vector<SkString> families) { fFontFamilies = std::move(families); }
|
|
|
|
SkFontStyle getFontStyle() const { return fFontStyle; }
|
|
void setFontStyle(SkFontStyle fontStyle) { fFontStyle = fontStyle; }
|
|
|
|
SkScalar getFontSize() const { return fFontSize; }
|
|
void setFontSize(SkScalar size) { fFontSize = size; }
|
|
|
|
void setHeight(SkScalar height) { fHeight = height; }
|
|
SkScalar getHeight() const { return fHeight; }
|
|
|
|
void setLeading(SkScalar Leading) { fLeading = Leading; }
|
|
SkScalar getLeading() const { return fLeading; }
|
|
|
|
bool getStrutEnabled() const { return fEnabled; }
|
|
void setStrutEnabled(bool v) { fEnabled = v; }
|
|
|
|
bool getForceStrutHeight() const { return fForceHeight; }
|
|
void setForceStrutHeight(bool v) { fForceHeight = v; }
|
|
|
|
bool getHeightOverride() const { return fHeightOverride; }
|
|
void setHeightOverride(bool v) { fHeightOverride = v; }
|
|
|
|
private:
|
|
|
|
std::vector<SkString> fFontFamilies;
|
|
SkFontStyle fFontStyle;
|
|
SkScalar fFontSize;
|
|
SkScalar fHeight;
|
|
SkScalar fLeading;
|
|
bool fForceHeight;
|
|
bool fEnabled;
|
|
bool fHeightOverride;
|
|
};
|
|
|
|
struct ParagraphStyle {
|
|
ParagraphStyle();
|
|
|
|
bool operator==(const ParagraphStyle& rhs) const {
|
|
return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis &&
|
|
this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
|
|
this->fDefaultTextStyle == rhs.fDefaultTextStyle;
|
|
}
|
|
|
|
const StrutStyle& getStrutStyle() const { return fStrutStyle; }
|
|
void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
|
|
|
|
const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
|
|
void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
|
|
|
|
TextDirection getTextDirection() const { return fTextDirection; }
|
|
void setTextDirection(TextDirection direction) { fTextDirection = direction; }
|
|
|
|
TextAlign getTextAlign() const { return fTextAlign; }
|
|
void setTextAlign(TextAlign align) { fTextAlign = align; }
|
|
|
|
size_t getMaxLines() const { return fLinesLimit; }
|
|
void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
|
|
|
|
const SkString& getEllipsis() const { return fEllipsis; }
|
|
void setEllipsis(const std::u16string& ellipsis);
|
|
|
|
SkScalar getHeight() const { return fHeight; }
|
|
void setHeight(SkScalar height) { fHeight = height; }
|
|
|
|
bool unlimited_lines() const {
|
|
return fLinesLimit == std::numeric_limits<size_t>::max();
|
|
}
|
|
bool ellipsized() const { return fEllipsis.size() != 0; }
|
|
TextAlign effective_align() const;
|
|
bool hintingIsOn() const { return fHintingIsOn; }
|
|
void turnHintingOff() { fHintingIsOn = false; }
|
|
|
|
private:
|
|
StrutStyle fStrutStyle;
|
|
TextStyle fDefaultTextStyle;
|
|
TextAlign fTextAlign;
|
|
TextDirection fTextDirection;
|
|
size_t fLinesLimit;
|
|
SkString fEllipsis;
|
|
SkScalar fHeight;
|
|
bool fHintingIsOn;
|
|
};
|
|
} // namespace textlayout
|
|
} // namespace skia
|
|
|
|
#endif // ParagraphStyle_DEFINED
|