ElectronicObserverEN / ElectronicObserver

Electronic Observer is a game viewer for Kantai Collection.
Other
84 stars 20 forks source link

Browser font #103

Open myangelkamikaze opened 2 years ago

myangelkamikaze commented 2 years ago

Setting the browser font is possible by adding a style to the kancolle frame head: https://twitter.com/noro_006/status/1487288329372827648

WebView2 currently doesn't support accessing nested iframes, so it's not possible right now.

Script for testing:

let style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '@font-face { font-family: "font_j"; src: local("MS Gothic"); font-weight: normal; }';
style.innerHTML += '\n';
style.innerHTML += '@font-face { font-family: "font_j"; src: local("MS UI Gothic"); font-weight: bold; }';
document.getElementsByTagName('head')[0].appendChild(style);
myangelkamikaze commented 2 years ago

Disabling some security features lets you access the frame via js:

browserArgs.Add("--disable-web-security");
browserArgs.Add("--disable-site-isolation-trials");

From top level:

let style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '@font-face { font-family: "font_j"; src: local("MS Gothic"); font-weight: normal; }';
style.innerHTML += '\n';
style.innerHTML += '@font-face { font-family: "font_j"; src: local("MS UI Gothic"); font-weight: bold; }';
document.getElementById("game_frame").contentWindow.document.getElementById("htmlWrap").contentWindow.document.getElementsByTagName('head')[0].appendChild(style);
myangelkamikaze commented 1 year ago

With the initial implementation, the custom browser font gets applied as expected. image

The main problem currently seems to be that the game fails to display it correctly unless you load the default game font first. The failed display looks like this: image

The current procedure to make everything look correct would be:

  1. Enable custom browser font
  2. Enter the game (this will apply the custom font in the home port screen)
  3. Disable custom browser font
  4. Load all screens with text (the exact list of what needs to be loaded needs to be investigated)
  5. Enable custom browser font

We could make a dropdown that tracks the loaded screens (this would be handled in CustomRequestHandler.cs) and add a button to apply the font (5.) after everything is loaded. image

Note that this would have to be done after every game refresh, so it's a very annoying procedure, which is why I just hid the option for now.

The ideal solution would be to figure out why custom fonts cause the incorrect display, but I have no idea how to figure that out.