@@ -3,60 +3,48 @@ title: Porting *WBE* to Recent Software Releases
33...
44
55The code in this book was developed for and tested on particular
6- versions of the libraries it depends on, including Python 3.12, Skia
7- 87, Tk 8.6.14, DukPy 0.3.0, and PySDL2 0.9.15. This page documents
8- code changes necessary to port the code of *Web Browser Engineering*
9- to the most recent release of each library. It will be regularly
10- updated as new versions are released and tested.
11-
12- Porting to Skia 124
13- ===================
14-
15- The text of this book uses Skia 87, and the associated skia-python
16- 87.6 release. Skia 124, and the associated skia-python 124b7 release,
17- changes a couple of APIs used in this book. One major change is the
18- removal of `FilterQuality`, used in [Chapter 15](embeds.md), and its
19- replacement by `SamplingOptions`. This requires updating
20- `parse_image_rendering` like so :
6+ library versions, including Python 3.14, Skia 138, Tk 8.6.14, DukPy
7+ 0.3.0, and PySDL2 0.9.15. Earlier editions of the book, however,
8+ relied on earlier versions, and future editions might rely on later
9+ ones. This page documents code changes necessary to port the code of
10+ *Web Browser Engineering* to other relevant releases of each library.
11+ It will be regularly updated as new versions are released and tested.
12+
13+ Porting to Skia 87
14+ ==================
15+
16+ The text of this online book uses Skia 138, but the printed 1^st^
17+ edition used the earlier version 87. This earlier version was missing
18+ the `SamplingOptions` API used in [Chapter 15](embeds.md) of this
19+ book. Skia 87 instead provides the older `FilterQuality` API.
20+
21+ Readers of the 1^st^ edition thus saw a different implementation of
22+ `parse_image_rendering` :
2123
2224` ` ` {.python}
2325def parse_image_rendering(quality):
2426 if quality == "high-quality":
25- return skia.SamplingOptions(skia.CubicResampler.Mitchell())
27+ return skia.FilterQuality.kHigh_FilterQuality
2628 elif quality == "crisp-edges":
27- return skia.SamplingOptions(
28- skia.FilterMode.kNearest, skia.MipmapMode.kNone)
29+ return skia.FilterQuality.kLow_FilterQuality
2930 else:
30- return skia.SamplingOptions(
31- skia.FilterMode.kLinear, skia.MipmapMode.kLinear)
31+ return skia.FilterQuality.kMedium_FilterQuality
3232` ` `
3333
3434And changing the `execute` method of `DrawImage` like so :
3535
3636` ` ` {.python}
3737class DrawImage:
3838 def execute(self, canvas):
39- canvas.drawImageRect(self.image, self.rect, self.quality)
39+ paint = skia.Paint(
40+ FilterQuality=self.quality,
41+ )
42+ canvas.drawImageRect(self.image, self.rect, paint)
4043` ` `
4144
42- The new API is somewhat cleaner and more customizable.
45+ The `SDL_GL_SetAttribute` method calls in the `Browser` constructor
46+ were also not necessary on this older version.
4347
44- Finally, add these `SDL_GL_SetAttribute` calls to set GL version Skia
45- expects :
46-
47- ` ` ` {.python}
48- class Browser:
49- def __init__(self):
50- self.sdl_window = sdl2.SDL_CreateWindow(b'Browser',
51- sdl2.SDL_WINDOWPOS_CENTERED,
52- sdl2.SDL_WINDOWPOS_CENTERED,
53- WIDTH, HEIGHT,
54- sdl2.SDL_WINDOW_SHOWN | sdl2.SDL_WINDOW_OPENGL)
55-
56- sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_MAJOR_VERSION, 3)
57- sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_MINOR_VERSION, 2)
58- sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG, True)
59- sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_PROFILE_MASK,
60- sdl2.SDL_GL_CONTEXT_PROFILE_CORE)
61- ` ` `
62-
48+ We recommend new readers use a recent Skia version, as described in
49+ the main text, but the old code is documented here to preserve the
50+ code of the 1^st^ edition.
0 commit comments