logo
down
shadow

pdf.js: Get the text colour


pdf.js: Get the text colour

By : user2955287
Date : November 22 2020, 10:38 AM
I think the issue was by ths following , As Respawned alluded to, there is no easy answer that will work in all cases. That being said, here are two approaches which seem to work fairly well. Both having upsides and downsides.
Approach 1
code :
var CustomEvaluatorPreprocessor = (function() {
    function CustomEvaluatorPreprocessor(stream, xref, stateManager, resources) {
        EvaluatorPreprocessor.call(this, stream, xref, stateManager);
        this.resources = resources;
        this.xref = xref;

        // set initial color state
        var state = this.stateManager.state;
        state.textRenderingMode = TextRenderingMode.FILL;
        state.fillColorSpace = ColorSpace.singletons.gray;
        state.fillColor = [0,0,0];
    }

    CustomEvaluatorPreprocessor.prototype = Object.create(EvaluatorPreprocessor.prototype);

    CustomEvaluatorPreprocessor.prototype.preprocessCommand = function(fn, args) {
        EvaluatorPreprocessor.prototype.preprocessCommand.call(this, fn, args);
        var state = this.stateManager.state;
        switch(fn) {
            case OPS.setFillColorSpace:
                state.fillColorSpace = ColorSpace.parse(args[0], this.xref, this.resources);
            break;
            case OPS.setFillColor:
                 var cs = state.fillColorSpace;
                 state.fillColor = cs.getRgb(args, 0);
            break;
            case OPS.setFillGray:
              state.fillColorSpace = ColorSpace.singletons.gray;
              state.fillColor = ColorSpace.singletons.gray.getRgb(args, 0);
            break;
            case OPS.setFillCMYKColor:
              state.fillColorSpace = ColorSpace.singletons.cmyk;
              state.fillColor = ColorSpace.singletons.cmyk.getRgb(args, 0);
            break;
            case OPS.setFillRGBColor:
                state.fillColorSpace = ColorSpace.singletons.rgb;
                state.fillColor = ColorSpace.singletons.rgb.getRgb(args, 0);
            break;
        }
    };

    return CustomEvaluatorPreprocessor;
})();
var preprocessor = new CustomEvaluatorPreprocessor(stream, xref, stateManager, resources);
color: stateManager.state.fillColor
function parseColors(canvasImgData, texts) {
    var data = canvasImgData.data,
        width = canvasImgData.width,
        height = canvasImgData.height,
        defaultColor = [0, 0, 0],
        minVariance = 20;

    texts.forEach(function (t) {
        var left = Math.floor(t.transform[4]),
            w = Math.round(t.width),
            h = Math.round(t.height),
            bottom = Math.round(height - t.transform[5]),
            top = bottom - h,
            start = (left + (top * width)) * 4,
            color = [],
            best = Infinity,
            stat = new ImageStats();

        for (var i, v, row = 0; row < h; row++) {
            i = start + (row * width * 4);
            for (var col = 0; col < w; col++) {
                if ((v = data[i] + data[i + 1] + data[i + 2]) < best) { // the darker the "better"
                    best = v;
                    color[0] = data[i];
                    color[1] = data[i + 1];
                    color[2] = data[i + 2];
                }
                stat.addPixel(data[i], data[i+1], data[i+2]);
                i += 4;
            }
        }
        var stdDev = stat.getStdDev();
        t.color = stdDev < minVariance ? defaultColor : color;
    });
}

function ImageStats() {
    this.pixelCount = 0;
    this.pixels = [];
    this.rgb = [];
    this.mean = 0;
    this.stdDev = 0;
}

ImageStats.prototype = {
    addPixel: function (r, g, b) {
        if (!this.rgb.length) {
            this.rgb[0] = r;
            this.rgb[1] = g;
            this.rgb[2] = b;
        } else {
            this.rgb[0] += r;
            this.rgb[1] += g;
            this.rgb[2] += b;
        }
        this.pixelCount++;
        this.pixels.push([r,g,b]);
    },

    getStdDev: function() {
        var mean = [
            this.rgb[0] / this.pixelCount,
            this.rgb[1] / this.pixelCount,
            this.rgb[2] / this.pixelCount
        ];
        var diff = [0,0,0];
        this.pixels.forEach(function(p) {
            diff[0] += Math.pow(mean[0] - p[0], 2);
            diff[1] += Math.pow(mean[1] - p[1], 2);
            diff[2] += Math.pow(mean[2] - p[2], 2);
        });
        diff[0] = Math.sqrt(diff[0] / this.pixelCount);
        diff[1] = Math.sqrt(diff[1] / this.pixelCount);
        diff[2] = Math.sqrt(diff[2] / this.pixelCount);
        return diff[0] + diff[1] + diff[2];
    }
};


Share : facebook icon twitter icon
Setting the background colour/highlight colour for a given string range using Core Text

Setting the background colour/highlight colour for a given string range using Core Text


By : Kyle Novak
Date : March 29 2020, 07:55 AM
it helps some times In the end, I had to use the Core Text metrics methods (getting the range, bounds, origins of lines etc) to calculate the bounding rectangle of the link. Once I had a rect for each line the link spanned, I drew the background into the context before redrawing the text above it.
Seems like a hell of a lot of work, but it works.
Changing default text colour and still showing disabled menu items in different colour

Changing default text colour and still showing disabled menu items in different colour


By : MickJagger
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You can use a drawable as the text colour, and in drawable you can use selector to select the colour according to enabled status. Using following drawable definition as colour will make your disabled menu items grey and the rest black.
In e.g. res/drawable/default_text_colour.xml:
code :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@android:color/darker_gray"/>
    <item android:color="@android:color/black"/>
</selector>
<item name="android:textColor">@drawable/default_text_colour</item>
In Eclipse, how to change the colour of the selected console text's highlighting colour?

In Eclipse, how to change the colour of the selected console text's highlighting colour?


By : Maria Sanchez
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Unfortunately that appears to be a color setting which cannot be changed within Eclipse.
On Windows 10 it definitely uses the operating system default for Selected Text (which for me is blue), but you can change it through the Personalize settings for Windows. I verified this, but obviously that will impact all your applications, not just the Eclipse Console, so it's not a very good option.
how can I change specific menu item text colour? background changing but text colour not changing?

how can I change specific menu item text colour? background changing but text colour not changing?


By : Jonathan
Date : March 29 2020, 07:55 AM
around this issue I have used following CSS codes in order to change specific menu item background and text color in an wordpress site. After applying the code, Background color has been changed but text color not changing. Can anyone help me please to make it work. My CSS codes are as follows which I have used (please note that same code I have used in different website that worked): , It's just your selector not enough specificity It should be
code :
#main-menu ul li a:hover 
.reserve-menu a:hover
How to change all text colour to default colour (Black for Text, Grey for Hint) instead of white

How to change all text colour to default colour (Black for Text, Grey for Hint) instead of white


By : user2162388
Date : March 29 2020, 07:55 AM
This might help you Currently all my text and hint colour by default is all white, although I do ok when I'm able to change them in xml file, but certain stuff like TextInputLayout text counter doesn't allow colour change , AndroidManifest was modified like this:
code :
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomTheme">
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:textColor">#000</item> //black color for text
        <item name="android:textColorHint">#939393</item> //Gray color for hint
    </style>
</resources>
Related Posts Related Posts :
  • Mocha JS: How to reuse assertions within a spec?
  • Is ember.js stable enough to use in a real world project?
  • jQuery Load() not loading within div
  • encode stream from webCam h264
  • Regex to find pattern, return subpattern
  • Why does this regex to remove empty <p></p> tags from a string fail?
  • Rails: pass data to javascript
  • Quickest way to check if a number is in a set?
  • Phonegap events online/offline not working
  • In HTML5, please explain the meaning of '?' in the statement
  • Form to use AJAX rather than a page refresh but also utilise error handling?
  • JQuery Script looping error
  • different size divs align top left
  • Image fade-in when webpage finishes loading
  • Seeking HTML5 audio element causes delay (breaks sync)
  • How can I read & write data to a new tab in Firefox?
  • jQuery or JS turn all words into italic type
  • iOS css -webkit-transform: scale doesn't offset touch events
  • Populate select list using javascript
  • Can you work out why my .js file doesn't seem to be linking to my html?
  • Make slideToggle effect only one element at a time
  • Output sound using JavaScript
  • What is the analytics.js equivalent of _trackPageview found in ga.js
  • How can I check if a JS file has been included already?
  • hasClass and condition not working
  • EDITED: I'm having issues with a button and its function
  • Importing XML in HTML with javascript
  • Create new function in contentScriptFile in Firefox extension
  • Should I build Node.js from source or download the OS X installer?
  • How to enforce integer sizes in JS? (TypeScript?)
  • How to update the JSON object without deleting old values using javascript
  • Reading a javascript variable containing a string into another file
  • Possible to prevent 403 errors from logging to the web console?
  • Jquery Accordion - Expand and collapse div on hover
  • jquery .hide() function - Hide mobile, Display Desktop
  • Holding password in javascript variable - security implications?
  • JQPlot trouble to render vertical stacked bar and horizontal legend
  • counts days inbetween then add class to those days with nested divs?
  • Marionette.js with Rails (Devise) Authentication
  • javascript anonymous function evaluation idiom
  • Why am I losing the decimal when working this equation in Javascript?
  • Site redirects to index.php after being open while making calls to an API using AJAX
  • How to determine when multiple callbacks are all done
  • How to update Yeoman dependencies?
  • How can I do a /resolve with the Soundcloud Javascript SDK?
  • I'm not able to call a named callback function
  • How to get value of Paragraph element contained in <div> in HTML using JavaScript
  • Javascript - Get value from textbox and save it on a string
  • Backbonejs collection not populated, but fetch works
  • when function's internal [[scope]] property is assigned?
  • Wrapping around the edges in a 2d array (game of life)?
  • Clone div with all nested elements along with events in pure javascript
  • How to get response text?
  • Setting and retrieving cookies in javascript
  • Passing parameter with double quotes
  • finding the meaning of the obfuscated javascript
  • Socket.io - Sending data from a pusher stream to the client
  • How to determine the visibility li's in a scrollable ul
  • How to create Scrolling Effect like Grouek website
  • How to display a state in parents template in ui-router
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org