Overlapping HTML Content In WebView, when using: webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); - android-layout

So I load some simple HTML into a webview.
The html is in the format: (it is extracted html, therefore no body tags.
<p>..blah</p>
<div style="text-align:center;">
<a href="http://services.runescape.com/m=rswikiimages/en/2012/5/combat1-18140712.jpg" target="_blank">
<img src="http://services.runescape.com/m=rswikiimages/en/2012/5/combat1_thumb-18140804.jpg"></a></div>
<p>..blah</p>
In the webview activity class I add:
webInfo = "<body style=\"color:white;font-size:15px\">" + webInfo + "</body>";
//for setting the size and color of the text
I use the following to load the html:
webview.loadDataWithBaseURL(null,webInfo,"text/html","UTF-8",null);
// webInfo is an html string
and I do the following so that it doesn't scroll horizontally and so that the image fits within the screen.
webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);|
If I don't use SINGLE_COLUMN, I'm always scrolling horizontally, even though the text fits nicely within the page. I thought it had finally solved the problem but I get overlapping html when i load it. This fixes itself if I zoom slightly in or out with my fingers.
Here's a picture of whats happening:
Question 1:
How do I fix that problem and display the image so it fits in the screen and no horizontal scrolling is required?
Question 2:
I've also been having trouble getting rid of the weird symbols too, my 's show up really weird.Tried using several different encodings like UTF-8, US-ACSII and lots of Windows ones, none of them seem to work to get rid of the symbols.
I hope I've been clear, any help is appreciated, I've been fiddling with this for a while O_O...

Add in webview settings:
webSettings.setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING) //handle for font overlapping.

Related

Weasyprint output format issue - how to use CSS #page?

I used to use wkhmtltopdf to print some webpages but unfortunately it doesn't work anymore with some modern websites.
I found weasyprint which I tried in command line. The output has all the contents but text is cropped probably due to page size.
The website tells this is customizable in CSS (https://weasyprint.readthedocs.io/en/stable/tutorial.html#adjusting-document-dimensions). I'm not a web expert and don't really know what to do here. Should I copy and edit the source code of the webpage ? Where should it be inserted then ?
Here is sample webpage I'd like to print properly as a pdf:
https://korben.info/8-clients-alternatifs-pour-spotify.html
Has anyone succeeded in proper printing with weasyprint ?
Thank you for your help.
Adjusting Document Dimensions
Currently, WeasyPrint does not provide support for adjusting page size or document margins via command-line flags. This is best accomplished with the CSS #page at-rule. Consider the following example:
#page {
size: Letter; /* Change from the default size of A4 */
margin: 2.5cm; /* Set margin on each page */
}
#page is a CSS media query, so you have to write down the code in a .css file.
Once done you can call
weasyprint -s path/to/css/file input output
Notice that complex pages are usually bad rendered by weasyprint, as there are few not-supported style tags (calc, var, overflow on precise axis, ecc..).
Let me say that working like taht is a mess, if you need to do complex things consider to use weasyprint as a Python lib and not in standalone mode, so you can process sources and achieve better results in whatever you need to do.
Hope it helps.
Hele.

Reader view breaks Javascript protecting images from right-click

I know protecting images is far from foolproof. However, clients ask for it, so I have Javascript on a site which is designed to prevent right-click saving/downloading.
It appears that Reader View ignores both the Javascript and the site's CSS. I tried to add {display:none} based on a rule .moz-reader-content (Firefox). I've assumed this is the case in all browsers.
Searching hasn't turned up a means of detecting reader view either.
Does anyone have any suggestions or know of a solution for this problem?
As you know there are no full-proof solutions. No matter what you do, if it's visible it can be copied. (With a screenshot as a last resort).
With that being said, a simple and surprisingly effective solution is just to overlay each image a transparent .png file.
<div id="imagecontainer" style="position:relative;">
<img src="yourimage.png" style="position:absolute;top:0px;left:0px;">
<img src="transparent-overlay.png" style="position:absolute;top:0px;left:0px;">
</div>
Right-clicking on the image, would then click on the overlay and not the image itself. (Of course, you'll want to give the overlay a less obvious name).
Additionally, you should watermark the image itself.
For getting around Reader View issues (I'm not sure which Reader View you're talking about btw), you could try using javascript to actually fill the images themselves. (Assuming your reader view doesn't permit js).
eg:
var i = document.createElement('img');
var o = document.createElement('img');
i.src = 'yourimage.png';
o.src = 'transparent-overlay.png';
document.getElementById('imagecontainer').appendChild(i);
document.getElementById('imagecontainer').appendChild(o);
In the latter js example you'd also need to set your css styles to absolute position the two images within #imagecontainer.

SVG file with xlink to another page in AMP project

I have an SVG file containing a number of xlinks that navigate to a different page. For example:
<a xlink:href="us/ak">...</a>
The SVG is a US map, and I'd be happy to provide it, but it's too big to include here.
When I try to use this SVG in an AMP page, the xlinks don't work. I see in the AMP spec that xlinks in an SVG are required to have a target URI starting with "#", so I think that's why my xlink isn't working. It behaves the same whether I use an amp-img or img tag.
It works fine if I put it in an img tag on a non-AMP page.
Is there a way to get my links to go to a new page, and not just to a #-link on the same page?
The color change on hover also stops working when I put the SVG on an AMP page, but I'm tackling one problem at a time.
If you just want to link to another page, <a href="..."> should work...

Can't click "through" fixed div menu

I'm having problems with my fixed menu. As you can see of the example beneath it's not possible to click the links "VingÄrde, Dyrkning..." because of the div box with the fixed menu on top of it. I've tried ordering the layers with z-index but I just can't get it to work. Can anybody help me out?
http://itu.dk/people/mbul/humlum/
And if anyone by the way have a method on auto adjusting the height of the page so it covers the whole viewport I would be very glad to hear from you :-) In the website version above I've set the height manually to 1000px which is not preferable
Thank you!
You need to put all the wrappers' elements outside of it and put them after the left-page container and before the right-page container. Finally, remove the wrapper, it seems unnecessary for the page in order to work.
I fixed it through Chrome's dev tools, but I assume it should work if you modify the html that way.
The body should look like this:
<div id="left_page_container">...</div>
<div class="nav_humlunvim">...</div>
<div class="nav_butik">...</div>
<div class="nav_blog">...</div>
<div class="nav_kontakt">...</div>
<div id="right_page_container">...</div>
Hope it helps; as an extra observation it is more common to use "hyphen-separated-names" for selectors than to use "snake_case_names" :)

Inline image in xslfo is rendered as block

I am facing an issue with XSLFO - FOP image rendering, I have several images of different size.
some of the small images are aligned inline with the text and some are big images that occupies a defined space, While displaying big images it would go beyond the viewport and i found a working solution at the Yahoo groups to restrict it within the viewport, however the given soultion renders both small and big images as block. but i need to render inline image as inline itself and not as block.
I am using following code to render image
<fo:external-graphic src="file:{./#src}" width="90%" content-width="scale-to-fit" scaling="uniform" content-height="100%" vertical-align="middle"/>
Image tag doesn't contain any information about inline or block.
Sample:
<img src="images/real_world_example.jpg" />
Text in the above image should align next to the image
Thanks in advance.
I can't test it but I think that the problem is with your width="90%". Simply delete it, it should work as you expect.

Resources