如何在iOS上使用CoreGraphics渲染的pdf转换文本颜色? [英] How would I invert text color on a pdf rendered with CoreGraphics on iOS?

查看:147
本文介绍了如何在iOS上使用CoreGraphics渲染的pdf转换文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用开源PDF查看库(VFR PDF Reader https://github.com/vfr/读者)。我正在尝试实现夜间模式或带有白色文本的黑色背景。我可以将背景设置为任何喜欢的颜色,但是无法更改文字颜色。您可以在 https:// github上看到可以修改背景颜色的位置。 com / vfr / Reader / blob / master / Sources / ReaderContentPage.m 中的 drawLayer方法。它只是在更改呈现PDF的矩形的颜色。

I am using an open-source PDF viewing library (VFR PDF Reader https://github.com/vfr/Reader). I'm trying to implement "night mode" or black background with white text. I can get the background to any color I like but I can't get the text color to change. You can see where you can modify the background color at https://github.com/vfr/Reader/blob/master/Sources/ReaderContentPage.m in the "drawLayer" method. It is simply changing the color of the rectangle the PDF is rendered on.

我的问题是:是否可以对上下文执行某些操作,以使pdf中的文本更改颜色(在我的情况下,我希望使用白色文本) ?问题所在的行看起来像这样(行558):

My question is: is there something I can do to the "context" that would cause the text in the pdf to change color (in my case I want white text)? The line in question looks like this (line 558):

CGContextDrawPDFPage(context, _PDFPageRef); // Render the PDF page into the context


推荐答案

我解决夜视的方法:

1)我在NSUserDefault中跟踪用户的偏好(夜间模式或白天模式)

1)I keep track of user preference (night mode or Day mode) in NSUserDefault

2)在

- (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)context
{

a)检索用户首选项

NSString *userViewMode = [[NSUserDefaults standardUserDefaults] objectForKey:@"DayOrNightSetting"];

b)将CGContextRef的背景色设置为白色

b) set the back ground color of the CGContextRef to white

 CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);

c)将CGContextDrawPage(Context,_PDFPageRef)替换为:

c) replace CGContextDrawPage(Context,_PDFPageRef) with :

if ([userViewMode isEqualToString:@"Night"]) {
        CGContextSetBlendMode(context, kCGBlendModeDestinationAtop);

        CGContextDrawPDFPage(context, _PDFPageRef);
        CGContextSetBlendMode(context, kCGBlendModeExclusion);
        CGContextDrawPDFPage(context, _PDFPageRef);
    }
    else
    {
       CGContextSetBlendMode(context,kCGBlendModeNormal);
    CGContextDrawPDFPage(context, _PDFPageRef);
    }

这篇关于如何在iOS上使用CoreGraphics渲染的pdf转换文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆