SkXPS: clean up SkConstexprMath
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2000853003 Review-Url: https://codereview.chromium.org/2000853003
This commit is contained in:
parent
a9ef92a5ed
commit
bfa9275968
@ -22,7 +22,6 @@
|
||||
'../src/utils', # needed to get SkBitSet.h
|
||||
],
|
||||
'sources': [
|
||||
'../src/xps/SkConstexprMath.h',
|
||||
'../src/xps/SkDocument_XPS.cpp',
|
||||
'../src/xps/SkXPSDevice.cpp',
|
||||
'../src/xps/SkXPSDevice.h',
|
||||
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkConstexprMath_DEFINED
|
||||
#define SkConstexprMath_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
#include <limits.h>
|
||||
|
||||
template <uintmax_t N, uintmax_t B>
|
||||
struct SK_LOG {
|
||||
//! Compile-time constant ceiling(logB(N)).
|
||||
static const uintmax_t value = 1 + SK_LOG<N/B, B>::value;
|
||||
};
|
||||
template <uintmax_t B>
|
||||
struct SK_LOG<1, B> {
|
||||
static const uintmax_t value = 0;
|
||||
};
|
||||
template <uintmax_t B>
|
||||
struct SK_LOG<0, B> {
|
||||
static const uintmax_t value = 0;
|
||||
};
|
||||
|
||||
template<uintmax_t N>
|
||||
struct SK_2N1 {
|
||||
//! Compile-time constant (2^N)-1.
|
||||
static const uintmax_t value = (SK_2N1<N-1>::value << 1) + 1;
|
||||
};
|
||||
template<>
|
||||
struct SK_2N1<1> {
|
||||
static const uintmax_t value = 1;
|
||||
};
|
||||
|
||||
/** Compile-time constant number of base n digits in type t
|
||||
if the bits of type t are considered as unsigned base two.
|
||||
*/
|
||||
#define SK_BASE_N_DIGITS_IN(n, t) (\
|
||||
SK_LOG<SK_2N1<(sizeof(t) * CHAR_BIT)>::value, n>::value\
|
||||
)
|
||||
/** Compile-time constant number of base 10 digits in type t
|
||||
if the bits of type t are considered as unsigned base two.
|
||||
*/
|
||||
#define SK_DIGITS_IN(t) SK_BASE_N_DIGITS_IN(10, (t))
|
||||
|
||||
// Compile-time constant maximum value of two unsigned values.
|
||||
template <uintmax_t a, uintmax_t b> struct SkTUMax {
|
||||
static const uintmax_t value = (b < a) ? a : b;
|
||||
};
|
||||
|
||||
#endif
|
@ -18,9 +18,9 @@
|
||||
#include <XpsObjectModel.h>
|
||||
#include <T2EmbApi.h>
|
||||
#include <FontSub.h>
|
||||
#include <limits>
|
||||
|
||||
#include "SkColor.h"
|
||||
#include "SkConstexprMath.h"
|
||||
#include "SkData.h"
|
||||
#include "SkDraw.h"
|
||||
#include "SkEndian.h"
|
||||
@ -190,6 +190,10 @@ bool SkXPSDevice::beginSheet(
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T> static constexpr size_t sk_digits_in() {
|
||||
return static_cast<size_t>(std::numeric_limits<T>::digits10 + 1);
|
||||
}
|
||||
|
||||
HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page,
|
||||
const unsigned int pageNum,
|
||||
IXpsOMImageResource** image) {
|
||||
@ -202,10 +206,9 @@ HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page,
|
||||
"Could not create thumbnail generator.");
|
||||
|
||||
SkTScopedComPtr<IOpcPartUri> partUri;
|
||||
static const size_t size = SkTUMax<
|
||||
SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + SK_DIGITS_IN(pageNum),
|
||||
SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png")
|
||||
>::value;
|
||||
constexpr size_t size = SkTMax(
|
||||
SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + sk_digits_in<decltype(pageNum)>(),
|
||||
SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png"));
|
||||
wchar_t buffer[size];
|
||||
if (pageNum > 0) {
|
||||
swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum);
|
||||
@ -229,8 +232,9 @@ HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page,
|
||||
|
||||
HRESULT SkXPSDevice::createXpsPage(const XPS_SIZE& pageSize,
|
||||
IXpsOMPage** page) {
|
||||
static const size_t size = SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage")
|
||||
+ SK_DIGITS_IN(fCurrentPage);
|
||||
constexpr size_t size =
|
||||
SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage")
|
||||
+ sk_digits_in<decltype(fCurrentPage)>();
|
||||
wchar_t buffer[size];
|
||||
swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage",
|
||||
this->fCurrentPage);
|
||||
|
Loading…
Reference in New Issue
Block a user