2015-01-05 19:17:27 +00:00
|
|
|
Tips & FAQ
|
|
|
|
==========
|
|
|
|
|
2015-12-22 15:08:12 +00:00
|
|
|
+ [Bitmap Subsetting](#bitmap-subsetting)
|
|
|
|
+ [Capture a `.skp` file on a web page in Chromium](#skp-capture)
|
2016-09-12 18:56:28 +00:00
|
|
|
+ [Capture a `.mskp` file on a web page in Chromium](#mskp-capture)
|
2015-12-22 15:08:12 +00:00
|
|
|
+ [How to add hardware acceleration in Skia](#hw-acceleration)
|
|
|
|
+ [Does Skia support Font hinting?](#font-hinting)
|
|
|
|
+ [Does Skia shape text (kerning)?](#kerning)
|
2016-04-26 11:49:45 +00:00
|
|
|
+ [How do I add drop shadow on text?](#text-shadow)
|
2015-12-22 15:08:12 +00:00
|
|
|
|
2015-07-09 13:58:06 +00:00
|
|
|
* * *
|
|
|
|
|
2016-09-26 14:27:04 +00:00
|
|
|
<span id="skp-capture">Capture a `.skp` file on a web page in Chromium</span>
|
|
|
|
-----------------------------------------------------------------------------
|
2015-07-09 13:58:06 +00:00
|
|
|
|
2018-03-13 14:57:34 +00:00
|
|
|
Use the script `experimental/tools/web_to_skp` , *or* do the following:
|
|
|
|
|
2015-07-08 17:56:01 +00:00
|
|
|
1. Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking`
|
2018-03-13 14:57:34 +00:00
|
|
|
2. Open the JS console (Ctrl+Shift+J (Windows / Linux) or Cmd+Opt+J (MacOS))
|
2015-07-08 17:56:01 +00:00
|
|
|
3. Execute: `chrome.gpuBenchmarking.printToSkPicture('/tmp')`
|
|
|
|
This returns "undefined" on success.
|
|
|
|
|
2016-07-06 13:10:25 +00:00
|
|
|
Open the resulting file in the [Skia Debugger](/dev/tools/debugger), rasterize it with `dm`,
|
2018-03-13 14:57:34 +00:00
|
|
|
or use Skia's `viewer` to view it:
|
2015-07-09 13:58:06 +00:00
|
|
|
|
|
|
|
<!--?prettify lang=sh?-->
|
2015-07-08 17:56:01 +00:00
|
|
|
|
|
|
|
out/Release/dm --src skp --skps /tmp/layer_0.skp -w /tmp \
|
|
|
|
--config 8888 gpu pdf --verbose
|
|
|
|
ls -l /tmp/*/skp/layer_0.skp.*
|
|
|
|
|
2018-03-13 14:57:34 +00:00
|
|
|
out/Release/viewer --skps /tmp --slide layer_0.skp
|
2015-07-09 13:58:06 +00:00
|
|
|
|
|
|
|
* * *
|
|
|
|
|
2016-09-26 14:27:04 +00:00
|
|
|
<span id="mskp-capture">Capture a `.mskp` file on a web page in Chromium</span>
|
|
|
|
-------------------------------------------------------------------------------
|
2016-09-12 18:56:28 +00:00
|
|
|
|
|
|
|
Multipage Skia Picture files capture the commands sent to produce PDFs
|
|
|
|
and printed documents.
|
|
|
|
|
2018-03-13 14:57:34 +00:00
|
|
|
Use the script `experimental/tools/web_to_mskp` , *or* do the following:
|
|
|
|
|
2016-09-12 18:56:28 +00:00
|
|
|
1. Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking`
|
2018-03-13 14:57:34 +00:00
|
|
|
2. Open the JS console (Ctrl+Shift+J (Windows / Linux) or Cmd+Opt+J (MacOS))
|
2016-09-12 18:56:28 +00:00
|
|
|
3. Execute: `chrome.gpuBenchmarking.printPagesToSkPictures('/tmp/filename.mskp')`
|
|
|
|
This returns "undefined" on success.
|
|
|
|
|
|
|
|
Open the resulting file in the [Skia Debugger](/dev/tools/debugger) or
|
|
|
|
process it with `dm`.
|
|
|
|
|
|
|
|
<!--?prettify lang=sh?-->
|
|
|
|
|
|
|
|
experimental/tools/mskp_parser.py /tmp/filename.mskp /tmp/filename.mskp.skp
|
|
|
|
ls -l /tmp/filename.mskp.skp
|
|
|
|
# open filename.mskp.skp in the debugger.
|
|
|
|
|
|
|
|
out/Release/dm --src mskp --mskps /tmp/filename.mskp -w /tmp \
|
|
|
|
--config pdf --verbose
|
2016-09-26 14:27:04 +00:00
|
|
|
ls -l /tmp/pdf/mskp/filename.mskp.pdf
|
2016-09-12 18:56:28 +00:00
|
|
|
|
|
|
|
* * *
|
|
|
|
|
2016-09-26 14:27:04 +00:00
|
|
|
<span id="hw-acceleration">How to add hardware acceleration in Skia</span>
|
|
|
|
--------------------------------------------------------------------------
|
2015-01-05 19:17:27 +00:00
|
|
|
|
2015-11-16 15:37:23 +00:00
|
|
|
There are two ways Skia takes advantage of specific hardware.
|
2015-01-05 19:17:27 +00:00
|
|
|
|
2018-01-10 14:55:05 +00:00
|
|
|
1. Custom bottleneck routines
|
2015-01-05 19:17:27 +00:00
|
|
|
|
2015-11-16 15:37:23 +00:00
|
|
|
There are sets of bottleneck routines inside the blits of Skia
|
|
|
|
that can be replace on a platform in order to take advantage of
|
|
|
|
specific CPU features. One such example is the NEON SIMD
|
2018-01-10 14:55:05 +00:00
|
|
|
instructions on ARM v7 devices. See [src/opts/](https://skia.googlesource.com/skia/+/master/src/opts/)
|
2015-01-05 19:17:27 +00:00
|
|
|
|
2015-07-09 13:58:06 +00:00
|
|
|
* * *
|
|
|
|
|
2016-09-26 14:27:04 +00:00
|
|
|
<span id="font-hinting">Does Skia support Font hinting?</span>
|
|
|
|
--------------------------------------------------------------
|
2015-01-05 19:17:27 +00:00
|
|
|
|
2018-01-10 14:55:05 +00:00
|
|
|
Skia has a built-in font cache, but it does not know how to actually render font
|
2015-12-14 17:50:15 +00:00
|
|
|
files like TrueType into its cache. For that it relies on the platform to
|
2018-01-10 14:55:05 +00:00
|
|
|
supply an instance of `SkScalerContext`. This is Skia's abstract interface for
|
2015-01-05 19:17:27 +00:00
|
|
|
communicating with a font scaler engine. In src/ports you can see support
|
2018-01-10 14:55:05 +00:00
|
|
|
files for FreeType, macOS, and Windows GDI font engines. Other font
|
2015-01-05 19:17:27 +00:00
|
|
|
engines can easily be supported in a like manner.
|
|
|
|
|
|
|
|
|
2015-12-14 17:50:15 +00:00
|
|
|
* * *
|
|
|
|
|
2016-09-26 14:27:04 +00:00
|
|
|
<span id="kerning">Does Skia shape text (kerning)?</span>
|
|
|
|
---------------------------------------------------------
|
2015-12-14 17:50:15 +00:00
|
|
|
|
2018-10-31 17:02:49 +00:00
|
|
|
Shaping is the process that translates a span of Unicode text into a span of
|
|
|
|
positioned glyphs with the apropriate typefaces.
|
|
|
|
|
|
|
|
Skia does not shape text. Skia provides interfaces to draw glyphs, but does
|
|
|
|
not implement a text shaper. Skia's client's often use
|
2015-12-14 18:03:31 +00:00
|
|
|
[HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz/) to
|
|
|
|
generate the glyphs and their positions, including kerning.
|
2015-12-14 17:50:15 +00:00
|
|
|
|
2016-05-03 17:18:30 +00:00
|
|
|
[Here is an example of how to use Skia and HarfBuzz
|
|
|
|
together](https://github.com/aam/skiaex). In the example, a
|
|
|
|
`SkTypeface` and a `hb_face_t` are created using the same `mmap()`ed
|
|
|
|
`.ttf` font file. The HarfBuzz face is used to shape unicode text into
|
2018-01-10 14:55:05 +00:00
|
|
|
a sequence of glyphs and positions, and the `SkTypeface` can then be
|
2016-05-03 17:18:30 +00:00
|
|
|
used to draw those glyphs.
|
|
|
|
|
2016-04-26 11:49:45 +00:00
|
|
|
* * *
|
|
|
|
|
2016-09-26 14:27:04 +00:00
|
|
|
<span id="text-shadow">How do I add drop shadow on text?</span>
|
|
|
|
---------------------------------------------------------------
|
2016-04-26 11:49:45 +00:00
|
|
|
|
|
|
|
<!--?prettify lang=cc?-->
|
|
|
|
|
|
|
|
void draw(SkCanvas* canvas) {
|
2018-12-28 19:37:13 +00:00
|
|
|
const SkScalar sigma = 1.65f;
|
2016-04-26 11:49:45 +00:00
|
|
|
const SkScalar xDrop = 2.0f;
|
|
|
|
const SkScalar yDrop = 2.0f;
|
|
|
|
const SkScalar x = 8.0f;
|
|
|
|
const SkScalar y = 52.0f;
|
|
|
|
const SkScalar textSize = 48.0f;
|
|
|
|
const uint8_t blurAlpha = 127;
|
2018-12-28 19:37:13 +00:00
|
|
|
auto blob = SkTextBlob::MakeFromString("Skia", SkFont(nullptr, textSize));
|
2016-04-26 11:49:45 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPaint blur(paint);
|
|
|
|
blur.setAlpha(blurAlpha);
|
2018-12-28 19:37:13 +00:00
|
|
|
blur.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, 0));
|
|
|
|
canvas->drawColor(SK_ColorWHITE);
|
|
|
|
canvas->drawTextBlob(blob.get(), x + xDrop, y + yDrop, blur);
|
|
|
|
canvas->drawTextBlob(blob.get(), x, y, paint);
|
2016-04-26 11:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
<a href='https://fiddle.skia.org/c/@text_shadow'><img src='https://fiddle.skia.org/i/@text_shadow_raster.png'></a>
|
|
|
|
|
2016-05-03 17:18:30 +00:00
|
|
|
* * *
|
|
|
|
|
2015-12-14 17:50:15 +00:00
|
|
|
<div style="margin-bottom:99%"></div>
|